Compile error: Invalid Outside Procedure

Anonymous
2022-08-10T21:49:04+00:00

<Moderator moved from Windows to Mac because Parallels is involved>

I recorded an "Insert Text From File" macro that gets the following error message when I attempt running it: "Compile error: Invalid Outside Procedure".

The VBA code is as follows (with an arrow pointing to the "Sub Macro8()" line, and highlighted in yellow):

Sub Macro8()

'

' Macro8 Macro

'

'

Selection.InsertFile FileName:="Test1.docx", Range:="", ConfirmConversions \_

    :=False, Link:=False, Attachment:=False

Please help!

Microsoft 365 and Office | Word | For home | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

18 answers

Sort by: Most helpful
  1. Anonymous
    2022-08-12T20:53:27+00:00

    To clarify, if the full path is x:\sig.docx, then I would manually add in the "x:" so that it's changed to: Selection.InsertFile FileName:="x:\Test1.docx"?

    The path is short because I'm doing through Parallels, and there's a shortcut to the folder on the Mac system through that drive.

    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 322K Reputation points MVP Volunteer Moderator
    2022-08-12T22:21:06+00:00

    As I do not know anything about a Mac or Parallels, barring any indiosyncrasy of that environment, adding the X:\ should do it.

    0 comments No comments
  3. Anonymous
    2022-08-13T17:37:15+00:00

    That didn't work, so it must be related to my using Parallels.

    0 comments No comments
  4. Jim G 134K Reputation points MVP Volunteer Moderator
    2022-08-13T18:40:44+00:00

    Hi

    Open the target document in Word for Windows in Parallels. In the VBE, in the Immediate Window type:

    ?curdir

    This will display the path to the folder containing the document. The full path is what is displayed plus the file name of the target document. In this example my target document is in the Mac OS Documents folder. My full path is:

    \Mac\Home\Documents\Test.docx

    This runs successfully inserting my Test.docx into my Word document in Windows:

    Sub testing()

    Selection.InsertFile FileName:="\\Mac\Home\Documents\Test.docx", Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
    

    End Sub

    Image

    0 comments No comments
  5. Anonymous
    2022-08-15T12:34:00+00:00

    Same thing happens when I try that - I open up to target document, I open up VBA, I type in the "Immediate" window ?curdir, and it gives me the same popup message in the VBA this time: "Compile Error: Invalid Outside Procedure."

    0 comments No comments