Open Excel file from Visual Basic

Thread Solved

Join Date: Mar 2006
Posts: 5
Reputation: seagull is an unknown quantity at this point 
Solved Threads: 1
seagull seagull is offline Offline
Newbie Poster

Re: Open Excel file from Visual Basic

 
0
  #11
Mar 29th, 2006
I forgot to say you need
Imports System.Runtime.InteropServices.Marshal for
ReleaseComObject()
Also I'm not sure if you actually need xlApp = nothing. Seems ok without it.

Dan
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Open Excel file from Visual Basic

 
0
  #12
Mar 29th, 2006
Nope, that's for .NET, which doesn't apply. Imports doesn't work in Legacy Vb's. However, setting the objects back to nothing is the proper way to go about this. Otherwise, you'll have tons of exe's (as objects) just floating around and eating up Ram.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 5
Reputation: seagull is an unknown quantity at this point 
Solved Threads: 1
seagull seagull is offline Offline
Newbie Poster

Re: Open Excel file from Visual Basic

 
0
  #13
Mar 29th, 2006
Yep. Sorry,

I should check which forum I'm in before trying to be clever.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 6
Reputation: harry.net is an unknown quantity at this point 
Solved Threads: 1
harry.net harry.net is offline Offline
Newbie Poster

Re: Open Excel file from Visual Basic

 
0
  #14
Mar 30th, 2006
Originally Posted by Comatose
Nope, that's for .NET, which doesn't apply. Imports doesn't work in Legacy Vb's. However, setting the objects back to nothing is the proper way to go about this. Otherwise, you'll have tons of exe's (as objects) just floating around and eating up Ram.
As you have mentioned VB 6 does not support import.
So what should I do for solving my problem?
I want to put my excel cells in an array.

I added this code also but still Exel.EXE is remaining in memory

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. System.Runtime.InteropServices.Marshal.ReleaseComObject (xlSht)
  2. System.Runtime.InteropServices.Marshal.ReleaseComObject (xlWBook)
  3. System.Runtime.InteropServices.Marshal.ReleaseComObject (xlApp)
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Open Excel file from Visual Basic

 
0
  #15
Mar 30th, 2006
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. System.Runtime.InteropServices.Marshal.ReleaseComObject (xlSht)
  2. System.Runtime.InteropServices.Marshal.ReleaseComObject (xlWBook)
  3. System.Runtime.InteropServices.Marshal.ReleaseComObject (xlApp)
will not work in vb6. That, too, is vb.net. In order to have the excel.exe application close from the process list, you are going to need to SET the objects to Nothing. Just like you set the objects to something (be it a workbook, or excel.application, or whatever), you have to then set it back to nothing. One thing about programming (in any language) that I truly love, and that is a pretty strict rule, is that "Anything That You Open, You Must Also Close." Now, while it may not seem that creating an object is the same as opening one, it is. If you do an if statement, what else must you do? You must End If, if you while you wend, if you do you loop, if you open you close, if you create, you destroy.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. set xlSht = nothing
  2. set xlWBook = nothing
  3. set xlApp = nothing
  4. set xltmp = nothing
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 6
Reputation: harry.net is an unknown quantity at this point 
Solved Threads: 1
harry.net harry.net is offline Offline
Newbie Poster

Re: Open Excel file from Visual Basic

 
0
  #16
Apr 1st, 2006
I have written this code but still Excel.EXE is in task manager
If I run the program 3 times 3 EXCEl.EXE is in task manager

I have another problem also
As I said I want to store the cells in an array as the form loads
The code is :
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ReDim Preserve Ucode2(101, 100)
  2. For i = 2 To xlSht.Rows.Count
  3. Ucode2(i, 0) = xlSht.Cells(i, 1).Value
  4. Ucode2(i, 1) = xlSht.Cells(i, 2).Value
  5. Next

But I have run time error '9' : Subscript out of range

Would you please help me?
Thanks.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Open Excel file from Visual Basic

 
0
  #17
Apr 1st, 2006
Attach your project.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 6
Reputation: harry.net is an unknown quantity at this point 
Solved Threads: 1
harry.net harry.net is offline Offline
Newbie Poster

Re: Open Excel file from Visual Basic

 
0
  #18
Apr 2nd, 2006
Originally Posted by Comatose
Attach your project.
I have attached my project.
I want to store the cells of the Excel file in an array named Ucode2
but there is runtime error 9 : subscript out of range.
Attached Files
File Type: zip New Folder.zip (4.3 KB, 76 views)
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Open Excel file from Visual Basic

 
0
  #19
Apr 2nd, 2006
And the excel document.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 6
Reputation: harry.net is an unknown quantity at this point 
Solved Threads: 1
harry.net harry.net is offline Offline
Newbie Poster

Re: Open Excel file from Visual Basic

 
0
  #20
Apr 3rd, 2006
Originally Posted by Comatose
And the excel document.
you did not check my zipped folder.
you can find the excel document file also in the folder.

thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC