VBA Print Formula To PDF

oconee1985

New Member
Joined
Apr 19, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Im new to using VBA and have been researching and trying different things and I think I almost have this to where I want it but have an error somewhere.

My goal is I want to be able to click my "Print Report" button and have it automatically print a pdf of my set area on my worksheet to a designated folder without me having to manually input the name or destination. In cell K10 I have the name/title that the PDF should be saved as and in Cell K11 I have the path of the folder that it should go to. When I click the button it prints the set area to the folder but does not save the pdf as the value in K10 instead it uses the current name of the excel workbook. Additionally, once it completes the function it opens the VBA window. Any help would be appreciated. Below is the formula I am using.
VBA Code:
Sub print_report()

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
        "C:\Users\Oconee1985\Desktop\Report\Test Template KC vs012.pdf" _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
    Range("M30").Select
    ActiveSheet.Shapes.Range(Array("Picture 6")).Select
    Selection.OnAction = "print_report"
    Range("K27").Select
    ActiveSheet.Shapes.Range(Array("Picture 6")).Select
    Range("K24").Select
    ActiveSheet.Shapes.Range(Array("Picture 6")).Select
    Application.Goto Reference:="print_report"

End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

yky

Well-known Member
Joined
Jun 7, 2011
Messages
1,835
Office Version
  1. 2010
Platform
  1. Windows
Replace the first line of code with the following and see if it works.
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _ ActiveSheet.Range("K11").value & "\" & ActiveSheet.Range("K10").value & ".pdf" _ , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _ :=False, OpenAfterPublish:=False
 

Watch MrExcel Video

Forum statistics

Threads
1,128,016
Messages
5,628,150
Members
416,296
Latest member
smartua

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top