none
Application.Run doesn't work with parameters in AutoExec function RRS feed

  • Question

  • Problem occurs on MS Office 2010 (x86), Windows 7 (x64).

    I have two templates: start.dot and main.dot. Both are digitally signed. 

    start.dot is placed in folder c:\Autostart and main.dot is placed in c:\Autostart\Macros. Both locations are added to trusted locations. c:\Autostart is set to be the Startup folder.

    Security settings are set to "Disable all macros except digitally signed macros".

    In start.dot I have function AutoExec, wich amongst other things, adds main.dot to AddIns and call Application.Run on sub that is in main.dot. This sub have parameters.

    This seems to work on most computers. But there are some stations, on wich macro fails... There is no error, the code just doesn't run on autostart. AutoExec function breaks right after Application.Run (I placed a message boxes before and after to see what happens - the second message box just didn't show up). Yet:

    - it works, if I remove parameters from sub

    - it works, if I change security settings to "Enable all macros"

    - it works, if I place cursor in AutoExec and press F5

    Does anyone know, what is going on here? On other computers, everything works fine, even if I don't sign macros (because they are in trusted location). Why does security settings change behaviour of Application.Run? Why would it work when run from VBA editor and not on autostart?

    Mabe I should pass parameters in some other way...? I do it like this:

    Application.Run "sub_name", "arg_value"

    Thursday, March 14, 2013 3:19 PM

All replies

  • This is a quick note to let you know that we are doing research on this issue. We will let you know if there is any progress.

    Have a nice day.

    Yoyo Jiang[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, March 18, 2013 7:39 AM
    Moderator
  • If you want to open file with autoopen procedure you must use this commend:

    'in Excel:
    Dim Wkb as workbook
    Set Wkb = Workbooks.Open(MyFile)
        Wkb.RunAutoMacros xlAutoOpen
    

    and as follow

    'in Word
    Dim doc As Document
    Set doc = Application.Documents.Open(MyFile)
        doc.RunAutoMacro wdAutoOpen
    



    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Monday, March 18, 2013 8:17 AM
    Answerer
  • I certainly DO NOT want to open a file with autoopen. Please read my post once more. How did you even come to that conclusion? :/

    Let me explain one more time.

    I have two templates.

    start.dot

    Public Sub AutoExec()
        MsgBox "before"
        Application.Run "Test1"
        MsgBox "after test1"
        Application.Run "Test2", "test"
        MsgBox "after test2"
    End Sub

    and main.dot

    Public Sub Test1()
        MsgBox "in test1"
    End Sub
    
    Public Sub Test2(ByVal test As String)
        MsgBox "in test2"
    End Sub

    start.dot is placed in folder c:\Autostart and main.dot is placed in c:\Autostart\Macros. Both locations are added to trusted locations. c:\Autostart is set to be the Startup folder. Security settings are set to "Disable all macros except digitally signed macros". Both my templates are digitally signed.

    If I run AutoExec function manually (by F5 in VBA editor), I can see message boxes:

    "before"
    "in test1"
    "after test1"
    "in test2"
    "after test2"

    Yet, when I start Word, I can see only:

    "before"
    "in test1"
    "after test1"

    So, AutoExec function run correctly, yet it fails to run a procedure, which has parameters.

    I can't be any clearer.


    • Edited by aurell Thursday, April 4, 2013 2:30 PM
    Thursday, April 4, 2013 2:08 PM
  • I was coll your code in Word and I see all 5 msgbox commends

    anyway, you can change this code like that:

    Public Sub AutoExec()
        MsgBox "before"
        Call Test1
        MsgBox "after test1"
        Call Test2("test")
        MsgBox "after test2"
    End Sub

    regards


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Friday, April 5, 2013 8:31 AM
    Answerer
  • @VBATools, let me repeat what I've already stated in my first post:

    "This seems to work on most computers. But there are some stations, on wich macro fails... There is no error, the code just doesn't run on autostart. AutoExec function breaks right after Application.Run (I placed a message boxes before and after to see what happens - the second message box just didn't show up). Yet:

    - it works, if I remove parameters from sub

    - it works, if I change security settings to "Enable all macros"

    - it works, if I place cursor in AutoExec and press F5"


    I can't use the Call method beacuse main.dot is NOT referenced in start.dot.

    I'm trying to get to the bottom of the problem. I want to know WHY on some computers macro works and on some it fails. I'm looking for a reason, not for a workaround.

    Friday, April 5, 2013 9:52 AM
  • Hi Aurell

    Unfortunately without being able to analyze the specific machines that are having the issue it is unlikely anyone on the forum would be able to explain why "This seems to work on most computers. But there are some stations, on which macro fails...".

    As you have already stated you are not looking for a workaround, my only suggestion would be for you to open a support incident by following the instructions in this article.
    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Best Regards,

    Donald M.
    Microsoft Online Community Support
    --------------------------------------------------------------------------------
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Thursday, April 18, 2013 3:11 PM