![]() |
Excel Change Focus to Outlook Contacts
Hi folks,
I've got code in Excel to see if there's an instance of Outlook running. Problem is, whether it is running or not already, the last command where I'm trying to change focus to Outlook Contacts creates a new instance of Outlook Contacts. Any suggestions on what I'm missing? Greatly appreciated! -Cole - Here my code thus far: ' This is button to change focus to Outlook Contacts: Dim ObjOutlook As Outlook.Application Dim bWasntRunning As Boolean bWasntRunning = False On Error Resume Next ' Try first to use an existing instance. Set ObjOutlook = GetObject(, "Outlook.Application") If Err Then ' Outlook isn't running, so start it. bWasntRunning = True Set ObjOutlook = CreateObject("Outlook.Application") End If Set objnamespace = ObjOutlook.GetNamespace("MAPI") ' Next line does set objFolder to "Contacts" Set objFolder = objnamespace.GetDefaultFolder(olFolderContacts) ' Then this next line is what opens a new instance of Outlook, even if Contacts are already open. objFolder.Display |
Excel Change Focus to Outlook Contacts
(untried)
objFolder.Visible = True "Cole" wrote: Hi folks, I've got code in Excel to see if there's an instance of Outlook running. Problem is, whether it is running or not already, the last command where I'm trying to change focus to Outlook Contacts creates a new instance of Outlook Contacts. Any suggestions on what I'm missing? Greatly appreciated! -Cole - Here my code thus far: ' This is button to change focus to Outlook Contacts: Dim ObjOutlook As Outlook.Application Dim bWasntRunning As Boolean bWasntRunning = False On Error Resume Next ' Try first to use an existing instance. Set ObjOutlook = GetObject(, "Outlook.Application") If Err Then ' Outlook isn't running, so start it. bWasntRunning = True Set ObjOutlook = CreateObject("Outlook.Application") End If Set objnamespace = ObjOutlook.GetNamespace("MAPI") ' Next line does set objFolder to "Contacts" Set objFolder = objnamespace.GetDefaultFolder(olFolderContacts) ' Then this next line is what opens a new instance of Outlook, even if Contacts are already open. objFolder.Display |
Excel Change Focus to Outlook Contacts
This (objFolder.Visible=True) did not work. In the Watch window, it
shows Value is Out of context. I've tried everything I could think of. Any further help would be greatly appreciated. Thx. JLGWhiz wrote: (untried) objFolder.Visible = True "Cole" wrote: Hi folks, I've got code in Excel to see if there's an instance of Outlook running. Problem is, whether it is running or not already, the last command where I'm trying to change focus to Outlook Contacts creates a new instance of Outlook Contacts. Any suggestions on what I'm missing? Greatly appreciated! -Cole - Here my code thus far: ' This is button to change focus to Outlook Contacts: Dim ObjOutlook As Outlook.Application Dim bWasntRunning As Boolean bWasntRunning = False On Error Resume Next ' Try first to use an existing instance. Set ObjOutlook = GetObject(, "Outlook.Application") If Err Then ' Outlook isn't running, so start it. bWasntRunning = True Set ObjOutlook = CreateObject("Outlook.Application") End If Set objnamespace = ObjOutlook.GetNamespace("MAPI") ' Next line does set objFolder to "Contacts" Set objFolder = objnamespace.GetDefaultFolder(olFolderContacts) ' Then this next line is what opens a new instance of Outlook, even if Contacts are already open. objFolder.Display |
All times are GMT +1. The time now is 05:06 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com