Outlook: Make visible
We find that when using Send as Attachment (actually, it's a macro of our own that runs instead of Send as Attachment in Word 2010), the Sent messages go to the Outlook Outbox and sometimes won't send unless the users manually gets into the message and Sends. This situation occurs only if Outlook is not running at the time the macro runs.
I have the following code which Activates Outlook if GetObject fails and I try CreateObject. I call this code as a function, but for testing purposes the Sub demonstrated my problem:
If Outlook is not running and I run this code. Outlook Inbox folder displays as expected. If I then close Outlook and run this macro again, it fails on the Outlook.GetNamesapce line, withe the message "the server cannot be found." If if End and run the macro again, it runs as expected. I can duplicate this over and over. On alternate tries, GetNamespace says the server does not exist or cannot be found. Any suggestions on how I modify my code to avoid this? (I am not on an EXchange server.)
Dim objNSpace As Object
Dim objExplorer As Object
Dim objFolder As Object
Set objNSpace = Outlook.GetNamespace("MAPI")
Set objFolder = objNSpace.GetDefaultFolder(6) ' 6 = olFolderInbox
Set objExplorer = Outlook.Explorers.Add(objFolder, 0) ' 0 = olFolderDisplayNormal
Set objNSpace = Nothing
Set objExplorer = Nothing
Set objFolder = Nothing
What is Outlook? If it's a variable, I'd suggest using a different name. If not, you should be using an Object variable .
Yes, of course. Thank you.