A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Access Excel (whether already open or not) from Outlook



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 6th 09, 08:23 PM posted to microsoft.public.outlook.program_vba
wpiet
external usenet poster
 
Posts: 19
Default Access Excel (whether already open or not) from Outlook

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  
Old January 6th 09, 09:18 PM posted to microsoft.public.outlook.program_vba
Norman Yuan
external usenet poster
 
Posts: 14
Default Access Excel (whether already open or not) from Outlook

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  
Old January 6th 09, 09:30 PM posted to microsoft.public.outlook.program_vba
wpiet
external usenet poster
 
Posts: 19
Default Access Excel (whether already open or not) from Outlook

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 09:25 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.