none
How to execute a SHELL in WORD VBA? - Compile Error: "Expected variable or procedure, not module" RRS feed

  • Question

  • Hello i'm getting this error when i try to use a "Shell(" command for the  very first time:

    Compile Error:  "Expected variable or procedure, not module"

    And these apparent logically related references are checked off:

    Microsoft Word 14.0 Object Library

    Microsoft Scripting Runtime

    Microsoft Shell Controls and Automation

    But basically what i want to do is, after running that Find routine and copying all the  Find terms to a text file, i then after its run, use NOTEPAD

    to open that output file, right after the FIND has completed, so any help would be greatly appreciated!

    ---------------------------------------------------------------------------------

    Sub startNotepad()

        Call OpenNotePad("C:\TEST\test.txt")

    End Sub

    Public Function OpenNotePad(strFile As String)
       
        Dim x As Variant
        x = Shell("notepad.exe " & strFile, 1)
       
    End Function


    • Edited by bobk5444 Friday, February 8, 2013 4:48 PM
    Friday, February 8, 2013 4:41 PM

Answers

  • The error message indicates that you have given one of the modules in the Visual Basic Editor the same name as a procedure (Sub) or function. That confuses Visual Basic.

    For example, if you have named a module Shell, or startNotepad, or OpenNotePad, give this module a different name.


    Regards, Hans Vogelaar

    Friday, February 8, 2013 8:10 PM

All replies

  • The error message indicates that you have given one of the modules in the Visual Basic Editor the same name as a procedure (Sub) or function. That confuses Visual Basic.

    For example, if you have named a module Shell, or startNotepad, or OpenNotePad, give this module a different name.


    Regards, Hans Vogelaar

    Friday, February 8, 2013 8:10 PM
  • Yes that was it Hans! thanks very much! and that was a bit tricky as i really had to search around to find that macro! ok great Hans have a nice weekend and thanks for you're time!  bk
    Friday, February 8, 2013 11:30 PM