Can you show us a screen shot of the Visual Basic Editor with the macro displayed in the Code window,
Compile error: Invalid Outside Procedure
<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.
18 answers
Sort by: Most helpful
-
Doug Robbins - MVP - Office Apps and Services 322K Reputation points MVP Volunteer Moderator2022-08-10T23:17:42+00:00 -
Jay Freedman 205.8K Reputation points Volunteer Moderator2022-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:
-
Jay Freedman 205.8K Reputation points Volunteer Moderator2022-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.