1

i need help with a file name, debug show some mistake (syntax error) in saving process, that's probably filename construction. I'd appreciate some help:

 Sub zapiszpdf2()
Dim DATA As String
DATA = Format(Date, "dd-mm-yyyy")

    Columns("E:F").Select
    Selection.EntireColumn.Hidden = True

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=
   ActiveWorkbook.Path & "\" & "C_a_" & DATA & ".pdf", Quality:=xlQualityStandard,
        IncludeDocProperties:=True, IgnorePrintAreas:=False, From:=1, To:=1, OpenAfterPublish:=True, OpenAfterPublish:= _
        True

    Columns("D:G").Select

    Selection.EntireColumn.Hidden = False

End Sub

Found it! An extra "," and double "open after", as you said. I also get rid of "select". Thanks a lot.

 Sub zapiszpdf2()
Dim DATA As String
DATA = Format(Date, "dd-mm-yyyy")

Columns("E:F").EntireColumn.Hidden = True

 ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
       ActiveWorkbook.Path & "C_a_" & DATA & ".pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, From:=1, To:=1, OpenAfterPublish:=True


Columns("D:G").EntireColumn.Hidden = False

End sub

Ada Ada
  • 11
  • 2

2 Answers2

0

In your code, 'OpenAfterPublish:=True' has been written twice and you can just delete one.

 Sub zapiszpdf2()
Dim DATA As String
DATA = Format(Date, "dd-mm-yyyy")

Columns("E:F").Select
Selection.EntireColumn.Hidden = True

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=
   ActiveWorkbook.Path & "\" & "C_a_" & DATA & ".pdf", Quality:=xlQualityStandard,
        IncludeDocProperties:=True, IgnorePrintAreas:=False, From:=1, To:=1, OpenAfterPublish:=True

Columns("D:G").Select

Selection.EntireColumn.Hidden = False

End Sub

Hope that helps!

Lina
  • 261
  • 1
  • 4
  • My bad - i have deleted the second "open after", but there is still syntax error in: ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= ActiveWorkbook.Path & "\" & "C_a_" & DATA & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, From:=1, To:=1, OpenAfterPublish:=True – Ada Ada Aug 30 '18 at 09:22
0

i see two problems

first you have OpenAfterPublish:=True twice, just delete one

and second i thick you are not selecting the "activesheet"

try to put Sheets("NAME_OF_SHEET").Select before the export to PDF

thanks

Luis Curado
  • 724
  • 5
  • 16