-1

I'm trying to make a macro that exports only a specific area to PDF. I have multiple sheets in my workbook, but I can't use SaveAs with xlSelection because that parameter is bugged and it exports the entire workbook to a PDF. Here is the code that I have:

Sub Export()
'
' Export Macro
'
' Keyboard Shortcut: Option+Cmd+p
'
Range("B1:G32").Select

Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:="~:Desktop:Quote.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

End Sub

Please let me know if there is a solution I could try.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Alfredo C
  • 1
  • 2

1 Answers1

0

The following is my code, and it successfully save my stuff to pdf. I am saving the entire worksheet, not certain cells. Maybe you can modify my code to do what you want. Another thing is my code is written in Visual Studio with VB.net, so please make proper transformation to vba.

If saving cells dose not work for you, you can copy all the cells you want, paste them into a new worksheet, then save the entire new worksheet to pdf. It is achievable by vba.

 xlWorkSheet.ExportAsFixedFormat(Type:=Excel.XlFixedFormatType.xlTypePDF,
                                    Filename:=output_dir & "\" & test_set & "_" & sub_test & ".pdf",
                                    IgnorePrintAreas:=True,
                                    OpenAfterPublish:=False,
                                    Quality:=Excel.XlFixedFormatQuality.xlQualityStandard)
Joe
  • 841
  • 2
  • 10
  • 25