question

MichaelPropp-3388 avatar image
0 Votes"
MichaelPropp-3388 asked PeterNRoth-0931 commented

Expected End Sub Error

I have an odd Expected End Sub error that is occurring.
The macro below is activated manually by a button and it is in a workbook that is shared by multiple people.
When I run macro on my computer, it runs fine. When a coworker runs the macro, it has gives the following error:
Compile error: Expected End Sub

I don't know why this is occurring and I can't duplicate it on my computer.

 Public Sub AutoPDF()
 Dim strPath As String
 Dim strName As String
 Dim myFile As Variant
 Dim wbA As Workbook
 Dim strPathName As String
    
 Set wbA = ActiveWorkbook
    
 Worksheets("FS").Visible = xlSheetHidden
 Worksheets("Minutes").Visible = xlSheetHidden
    
 strPath = wbA.Path & "\"
 strName = wbA.Name & ".pdf"
 strPathName = strPath & strName
    
 myFile = Application.GetSaveAsFilename(InitialFileName:=strPathName, fileFilter:="PDF Files (*.pdf), *.pdf", Title:="Select Folder and File Name to Save")
    
 If myFile <> "false" Then
     wbA.ExportAsFixedFormat _
         Type:=xlTypePDF, _
         Filename:=myFile, _
         Quality:=xlQualityStandard, _
         IncludeDocProperties:=True, _
         IgnorePrintAreas:=False, _
         OpenAfterPublish:=True
 End If
    
 Worksheets("FS").Visible = xlSheetVisible
 Worksheets("Minutes").Visible = xlSheetVisible
    
 End Sub
office-vba-dev
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe you have a different version of Excel?


0 Votes 0 ·

We are both running Office 365 and both machines have been updated.

0 Votes 0 ·

1 Answer

PeterNRoth-0931 avatar image
0 Votes"
PeterNRoth-0931 answered PeterNRoth-0931 commented

MichaelPropp-3388 –
When you say ‘shared’, do you mean everyone uses one and the same workbook on one and the same machine?
Everyone has their own copy on separate machines, generated from a single source?

Go to the errant machine, open the module, look intensely at the End Sub line. Has it been altered? Delete the line. Add an empty line, and type in a new End Sub.
What happens?

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The workbook is stored on a local server that a few different people access. It is not used at the same time, mostly just for occasional data entry.
It is the same workbook file that everyone opens from the server.
The code above was copied from the errant machine.
I tried re-entering the End Sub text, but the error still occurs.

0 Votes 0 ·

Michael –
Are there any other Functions in the Module? Like something following this Sub?
What happens if you add a function

Private Sub XAutoPdf
Autopdf
End sub

after the errant Sub?

0 Votes 0 ·