Macro for saveas pdf for specific area in sheet of a workbook

RYALILAYR

New Member
Joined
Nov 5, 2017
Messages
2
Sir,

Good evening

am trying to write a macro for saveas a portion of excel worksheet in pdf format, but am unable to do the same since sintax errors coming, can any one can help me in this regard

one more thing is the file created should be name as content in cell "A1" of "sheet1"


Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
How about this?

Code:
Sub SaveAsPDF()
Dim r As Range
Dim ws As Worksheet
Dim strPath As String

Set ws = Sheets("Sheet1")
With ws
    strPath = Environ("UserProfile") & "\Desktop\" & .Range("A1").Value & ".pdf" 'You can modify this to change the save location
    Set r = .Range("$G$13:$L$25") 'Change to Print Area you want to export
    .PageSetup.PrintArea = r.Address
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPath, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=True
End With
End Sub
 
Upvote 0
Sir,


Sub SaveAsPDF()
Dim r As Range
Dim ws As Worksheet
Dim strPath As String

Set ws = Sheets("Sheet1")
With ws
strPath = Environ("UserProfile") & "\Desktop" & .Range("A1").Value & ".pdf" 'You can modify this to change the save location
Set r = .Range("$G$13:$L$25") 'Change to Print Area you want to export
.PageSetup.PrintArea = r.Address
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPath, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End With
End Sub


while running the aforesaid code it showing as error in exportasfixedformat and highlightes the lines as set in bold above.... kindly help me resolve this issue


Thanks
 
Upvote 0
You need to put a valid file name, like "TestFile" in cell A1.

Then modify the code to suit your needs
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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
Back
Top