![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
What am I doing wrong with this code?
Dim XL As Object On Error Resume Next Set XL = GetObject("Excel.Application") If XL Is Nothing Then Set XL = CreateObject("Excel.Application") End If XL.Visible = True I was under the impression that, if an instance of Excel is already running, GetObject would access it & 'Set' would assign it to the variable 'XL'. However, when I step through it, 'XL' = Nothing & CreateObject opens another instance of Excel. -- Will |
Ads |
#2
|
|||
|
|||
![]()
D you know GetObject() takes TWO optional arguments? The first one is
PathName, and the second one is the ClassName. Your code supplies "Excel.Application" as the first argument as PthName, which points to nothing and omits the second argument, thus, the GetObject() returns nothing. The correct code should be: Set XL=GetObject(, "Excel.Application) "wpiet" wrote in message ... What am I doing wrong with this code? Dim XL As Object On Error Resume Next Set XL = GetObject("Excel.Application") If XL Is Nothing Then Set XL = CreateObject("Excel.Application") End If XL.Visible = True I was under the impression that, if an instance of Excel is already running, GetObject would access it & 'Set' would assign it to the variable 'XL'. However, when I step through it, 'XL' = Nothing & CreateObject opens another instance of Excel. -- Will |
#3
|
|||
|
|||
![]()
That would be why.
I'll file that one under "You da man, Norman." Thanks -- Will "Norman Yuan" wrote: D you know GetObject() takes TWO optional arguments? The first one is PathName, and the second one is the ClassName. Your code supplies "Excel.Application" as the first argument as PthName, which points to nothing and omits the second argument, thus, the GetObject() returns nothing. The correct code should be: Set XL=GetObject(, "Excel.Application) "wpiet" wrote in message ... What am I doing wrong with this code? Dim XL As Object On Error Resume Next Set XL = GetObject("Excel.Application") If XL Is Nothing Then Set XL = CreateObject("Excel.Application") End If XL.Visible = True I was under the impression that, if an instance of Excel is already running, GetObject would access it & 'Set' would assign it to the variable 'XL'. However, when I step through it, 'XL' = Nothing & CreateObject opens another instance of Excel. -- Will |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook 2003 IPM.NOTE (Form) Exporting to Access or Excel | [email protected] | Outlook - Using Forms | 0 | December 5th 08 03:53 PM |
Why can't I export outlook contacts to Excel/Access, etc? | Pat | Outlook - Using Contacts | 2 | January 17th 07 12:04 AM |
Open and run Outlook from Excel automatically | Am | Outlook and VBA | 7 | November 2nd 06 10:40 PM |
Excel macro to create e-mail in Outlook Web Access | fitful_thought | Outlook - General Queries | 0 | April 15th 06 11:23 AM |
Can you import contacts from Outlook to Excel, Access, Word &how? | ericsayang | Outlook - General Queries | 1 | February 2nd 06 07:39 PM |