title: VBA Compile Error: Syntax Error for Saving Excel in PDF for Excel 2019
body: <p>I'm getting a "Compile Error: Syntax Error" when running the code below using Excel 2019. It works with the older version Excel, but not on 2019. How can I fix this and what's causing it?</p>
  
  <p><strong>the error line</strong></p>
  
  <pre><code>ReportSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
  
          ThisWorkbook.Path &amp; "\" &amp; Cell, _
  
          Quality:=xlQualityStandard, IncludeDocProperties:=True, _
  
          IgnorePrintAreas:=True, OpenAfterPublish:=False
  </code></pre>
  
  <p><strong>The entire code</strong></p>
  
  <pre><code>Option Explicit
  
  Private Sub CommandButton1_Click()
  
  
  
  Dim MyFolder As String, MyFile As String
  
  Dim StartTime As Double
  
  Dim MinutesElapsed As String
  
  Dim Filename As String
  
  Dim Cell As String
  
  Dim Counter As Long
  
  
  
              If ThisWorkbook.Sheets("Sheet1").Range("C7").Value = vbNullString Then
  
              MsgBox "Enter Tab Name"
  
              Exit Sub
  
  
  
              End If
  
  
  StartTime = Timer
  
  
  
              With Application.FileDialog(msoFileDialogFolderPicker)
  
                 .AllowMultiSelect = False
  
                 .Title = "Select a Folder"
  
                 If .Show = True Then
  
                 MyFolder = .SelectedItems(1)
  
                 End If
  
  
  
                 If .SelectedItems.Count = 0 Then Exit Sub
  
                 Err.Clear
  
              End With
  
  
              'Turns settings off
              Application.ScreenUpdating = False
  
              Application.DisplayStatusBar = False
  
              Application.EnableEvents = False
  
              Application.Calculation = xlCalculationManual
  
  
              MyFile = Dir(MyFolder &amp; "\", vbReadOnly)
  
  
  Do While MyFile &lt;&gt; ""
  
          DoEvents
  
          On Error GoTo 0
  
          Workbooks.Open Filename:=MyFolder &amp; "\" &amp; MyFile, UpdateLinks:=False
  
  
  Dim ReportSheet As Worksheet
  
  Dim MySheet As String
  
  Dim allColumns As Range
  
  
  
  MySheet = ThisWorkbook.Sheets("Sheet1").Range("C7").Value
  
  
  
  Set ReportSheet = Sheets(MySheet)
  
  Set allColumns = ReportSheet.Columns("N:S")
  
          allColumns.Hidden = True
  
  
  
          With ReportSheet.PageSetup
  
           .Zoom = False
  
           .FitToPagesWide = 1    '.FitToPagesTall = 1
  
          End With
  
  
  Filename = ActiveWorkbook.Name
  
  
  
  Cell = Replace(Filename, ".xlsx", ".PDF")   
  
      ReportSheet.Select
  
  
  
      ReportSheet.PageSetup.Orientation = xlLandscape
  
  
      ReportSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
  
          ThisWorkbook.Path &amp; "\" &amp; Cell, _
  
          Quality:=xlQualityStandard, IncludeDocProperties:=True, _
  
          IgnorePrintAreas:=True, OpenAfterPublish:=False
  
  
  
  Counter = Counter + 1
  
  0
  
          Workbooks(MyFile).Close SaveChanges:=False
  
          MyFile = Dir
  
  Loop
  
  
      'turns settings back on that you turned off before looping folders
  
  
  
          Application.ScreenUpdating = True
  
          Application.DisplayStatusBar = True
  
          Application.EnableEvents = True
  
          Application.Calculation = xlCalculationManual
  
  
  MinutesElapsed = Format((Timer - StartTime) / 86400, "hh:mm:ss")
  
  MsgBox "Successfully Converted " &amp; Counter &amp; " Files in " &amp; MinutesElapsed &amp; " minutes", vbInformation
  
  
  
  End Sub
  </code></pre>