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. Doug Robbins - MVP - Office Apps and Services 322K Reputation points MVP Volunteer Moderator
    2022-08-10T23:17:42+00:00

    Can you show us a screen shot of the Visual Basic Editor with the macro displayed in the Code window,

    0 comments No comments
  2. Jay Freedman 205.8K Reputation points Volunteer Moderator
    2022-08-11T00:55:36+00:00

    If what you posted is everything in the code window of the macro editor, then the problem appears to be the fact that there is no End Sub statement at the bottom of the macro. However, when I record the action (and get the same InsertFile statement) and then delete the End Sub statement from it, the error I see is the correct observation:

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2022-08-11T12:58:16+00:00

    See screenshot above

    0 comments No comments
  4. Anonymous
    2022-08-11T12:58:51+00:00

    I actually did include "End Sub" in it, see screenshot below.

    0 comments No comments
  5. Jay Freedman 205.8K Reputation points Volunteer Moderator
    2022-08-11T18:32:25+00:00

    You're correct. That macro looks completely legal, particularly now that I can see the macros that precede and follow it. Do they also get the same error when you run them, or do they operate correctly?

    If that's the only macro that misbehaves, delete it and reconstruct it by typing it instead of recording. If the others also don't work, try repairing Office.

    0 comments No comments