User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 456,554 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,457 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 156302 | Replies: 23 | Solved
Reply
Join Date: Mar 2006
Posts: 5
Reputation: seagull is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
seagull seagull is offline Offline
Newbie Poster

Re: Open Excel file from Visual Basic

  #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  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 108
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Open Excel file from Visual Basic

  #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  
Join Date: Mar 2006
Posts: 5
Reputation: seagull is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
seagull seagull is offline Offline
Newbie Poster

Re: Open Excel file from Visual Basic

  #13  
Mar 29th, 2006
Yep. Sorry,

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

Re: Open Excel file from Visual Basic

  #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

System.Runtime.InteropServices.Marshal.ReleaseComObject (xlSht)
System.Runtime.InteropServices.Marshal.ReleaseComObject (xlWBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject (xlApp)
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 108
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Open Excel file from Visual Basic

  #15  
Mar 30th, 2006
System.Runtime.InteropServices.Marshal.ReleaseComObject (xlSht)
System.Runtime.InteropServices.Marshal.ReleaseComObject (xlWBook)
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.

set xlSht = nothing
set xlWBook = nothing
set xlApp = nothing
set xltmp = nothing
Reply With Quote  
Join Date: Mar 2006
Posts: 6
Reputation: harry.net is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
harry.net harry.net is offline Offline
Newbie Poster

Re: Open Excel file from Visual Basic

  #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 :
ReDim Preserve Ucode2(101, 100)
For i = 2 To xlSht.Rows.Count
    Ucode2(i, 0) = xlSht.Cells(i, 1).Value
    Ucode2(i, 1) = xlSht.Cells(i, 2).Value
Next

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

Would you please help me?
Thanks.
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 108
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Open Excel file from Visual Basic

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

Re: Open Excel file from Visual Basic

  #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, 65 views)
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 108
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Open Excel file from Visual Basic

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

Re: Open Excel file from Visual Basic

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 4 (0 members and 4 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 5:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC