Compile Error: Invalid Outside Procedure

Anonymous
2024-02-26T16:05:50+00:00

Split from this thread.

getting another error can anyone help please.

Microsoft 365 and Office | Word | For home | Windows

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

4 answers

Sort by: Most helpful
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2024-02-26T16:10:10+00:00

    Your code ends with End Sub, but the corresponding line

    Sub macroname()

    at the beginning is missing.

    0 comments No comments
  2. HansV 462.4K Reputation points MVP Volunteer Moderator
    2024-02-26T16:11:47+00:00

    Based on your previous topic, insert the line

    Private Sub CommandButton1_Click()

    at the top of the code.

    0 comments No comments
  3. Charles Kenyon 158.8K Reputation points Volunteer Moderator
    2024-02-26T16:12:57+00:00

    Try

    strFileName:= ActiveDocument.Name or

    strFileName: =ActiveDocument.FullName

    Let the export as pdf procedure handle the extension. At worst, I expect you will end up with it tacked onto .docx as in myFileName.docx.pdf.

    Both Doug and Hans are much more proficient and competent vba coders than am I.

    0 comments No comments
  4. Jay Freedman 205.8K Reputation points Volunteer Moderator
    2024-02-26T17:33:00+00:00

    Based on your previous topic, insert the line

    Private Sub CommandButton1_Click()

    at the top of the code.

    Looking at this snippet from the previous thread,

    .

    you need one of the two lines in the box, but not both. If you restore the first line, the macro will run when you click the button named CommandButton1 (assuming this code is in a userform that contains such a button). If you restore the second line, the macro will run only when you manually choose to start it (assuming that you have a shortcut or QAT button assigned to it, or use the Alt+F8 "Macros" dialog).

    Also, if you type either line into the macro editor, VBA will automatically follow it with an End Sub statement, which you'll have to delete because there's already one at the end of the macro.

    1 person found this answer helpful.
    0 comments No comments