Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    855
    Thanks
    0
    Thanked 9 Times in 8 Posts

    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:

    Code:
    Sub MakeOutlookVisible()
        
        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
        objExplorer.Activate
            
        Set objNSpace = Nothing
        Set objExplorer = Nothing
        Set objFolder = Nothing
    End Sub
    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.)

    Many thanks.
    Last edited by richardbarrett; 2014-04-07 at 15:38.

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,870
    Thanks
    0
    Thanked 78 Times in 74 Posts
    What is Outlook? If it's a variable, I'd suggest using a different name. If not, you should be using an Object variable .
    Regards,
    Rory
    Microsoft MVP - Excel.

  4. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    855
    Thanks
    0
    Thanked 9 Times in 8 Posts
    Yes, of course. Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •