VB OLE Automation to Excel 
Author Message
 VB OLE Automation to Excel

Greetings,

Can you help this VB newbie?

I'd like to open an existing Excel file from within VB.  I've done some
reading at different web sites and gathered info at the Microsoft VB Home page
about the GetObject function. A lot of the reading material describes problems
with versions of software(VB and Excel) and application visibility.

Seems simple enough to code....right.

my computer setup is Windows 98, VB6 Pro, Excel 2000.

Code snippet

'Declare variable
Dim xlsapp As Object

' Get existing file from C Drive and open Excel
Set xlsApp = GetObject("C:\file path and name" , "Excel.Application")

'Do some programming here

'Close Excel references
xlsApp.Quit
Set xlsApp = Nothing

The above code returns a runtime error, debugging the error shows that the Set
xlsApp = Get Object......... (xlsApp = nothing, holding the cursor over
the above code line).....VB is not finding my file??

So what am I doing wrong?  Is there a standard programmers VB code syntax
module for opening an existing Excel file?  

Thanks for your help.

Ian



Tue, 23 Sep 2003 04:46:09 GMT  
 VB OLE Automation to Excel
Sounds like you haven't set a reference to the Excel type library in
Projects|References so VB doesn't know what Excel.Application is!!

Richard

Quote:

> Greetings,

> Can you help this VB newbie?

> I'd like to open an existing Excel file from within VB.  I've done some
> reading at different web sites and gathered info at the Microsoft VB Home
page
> about the GetObject function. A lot of the reading material describes
problems
> with versions of software(VB and Excel) and application visibility.

> Seems simple enough to code....right.

> my computer setup is Windows 98, VB6 Pro, Excel 2000.

> Code snippet

> 'Declare variable
> Dim xlsapp As Object

> ' Get existing file from C Drive and open Excel
> Set xlsApp = GetObject("C:\file path and name" , "Excel.Application")

> 'Do some programming here

> 'Close Excel references
> xlsApp.Quit
> Set xlsApp = Nothing

> The above code returns a runtime error, debugging the error shows that the
Set
> xlsApp = Get Object......... (xlsApp = nothing, holding the cursor over
> the above code line).....VB is not finding my file??

> So what am I doing wrong?  Is there a standard programmers VB code syntax
> module for opening an existing Excel file?

> Thanks for your help.

> Ian



Tue, 23 Sep 2003 05:34:33 GMT  
 VB OLE Automation to Excel
Quote:
>Subject: VB OLE Automation to Excel

>Date: 4/5/01 3:46 PM Central Daylight Time

>Greetings,

>Can you help this VB newbie?

>I'd like to open an existing Excel file from within VB.  I've done some
>reading at different web sites and gathered info at the Microsoft VB Home
>page
>about the GetObject function. A lot of the reading material describes
>problems
>with versions of software(VB and Excel) and application visibility.

>Seems simple enough to code....right.

>my computer setup is Windows 98, VB6 Pro, Excel 2000.

>Code snippet

>'Declare variable
>Dim xlsapp As Object

>' Get existing file from C Drive and open Excel
>Set xlsApp = GetObject("C:\file path and name" , "Excel.Application")

>'Do some programming here

>'Close Excel references
>xlsApp.Quit
>Set xlsApp = Nothing

>The above code returns a runtime error, debugging the error shows that the
>Set
>xlsApp = Get Object......... (xlsApp = nothing, holding the cursor over
>the above code line).....VB is not finding my file??

>So what am I doing wrong?  Is there a standard programmers VB code syntax
>module for opening an existing Excel file?  

>Thanks for your help.

>Ian

Hi,

Try the following instead:

Dim xlsapp As Excel.Application
Dim xlw As Workbook

Set xlsapp = CreateObject("Excel.Application")
Set xlw = GetObject("C:\file path and name")

Also, make sure the Excel Object Library is checked at Tools | References.

Yours may have worked if Excel was already running; I didn't try that.

HTH,
Merjet



Tue, 23 Sep 2003 06:14:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VB, OLE Automation and Excel

2. Excel Ole automation with VB.NET

3. Help on OLE Automation (VB 4.0 to Excel 97)

4. Deactivating Excel's ScreenUpdating in VB OLE automation routine

5. Accessing empty Excel cells via OLE automation from VB 3.0

6. Excel Charts using OLE Automation

7. OLE Automation of Excel from Access 7.0

8. OLE Automation with MS Excel 5.0

9. OLE Automation (control Word from Excel)

10. OLE Automation (control Word from Excel)

11. Getting the RIGHT Excel sheet with OLE automation - AddOLEObj

12. OLE Automation (control Word from Excel)

 

 
Powered by phpBB® Forum Software