none
CreateObject does not fire AutoExec RRS feed

  • Question

  • Hi,

    if I use CreateObject("Word.Application") from i.e. Excel, The Word instance does not fire the AutoExec macro located in a global template that loads with Word. Is this by design?

    Thanks,
    Peeter

    Thursday, February 7, 2013 10:54 AM

Answers

  • Hi Peeter

    The following code works...

    Sub StartWord()
        Dim app As Object
        
        Shell "winword.exe"
        Set app = GetObject(, "Word.Application")
        app.AutomationSecurity = msoAutomationSecurityLow
        app.Visible = True
        Set app = Nothing
    End Sub
    


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 11, 2013 7:22 AM
    Moderator

All replies

  • Hi pemok,

    Thanks for posting the MSDN Forum.

    It's based on my experience you program is a VBA subroutine, is it right? If it is, please take a look at following snippet. I hope it can help you.

    Option Explicit
    
    Sub test()
        Dim app As Object
        
        Set app = CreateObject("Word.Application")
        app.Run ("TestMarco")
    End Sub

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, February 8, 2013 1:51 AM
    Moderator
  • Thank you for your answer. This solution works but demands changes in the calling application. This can be a document solution product which ee have no control over. So my question is if word does not run autoexec when "started" this way. /peeter
    Friday, February 8, 2013 3:43 PM
  • Hi Peeter,

    It based on my experience that is the only way to approach your goal.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 11, 2013 3:51 AM
    Moderator
  • Hi Peeter

    The following code works...

    Sub StartWord()
        Dim app As Object
        
        Shell "winword.exe"
        Set app = GetObject(, "Word.Application")
        app.AutomationSecurity = msoAutomationSecurityLow
        app.Visible = True
        Set app = Nothing
    End Sub
    


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 11, 2013 7:22 AM
    Moderator
  • Thank you all for your interest in this matter.

    /Peeter

    Thursday, February 14, 2013 7:40 AM