I need VBA Code to save my Pricing sheets of all four region’s customer’s files to be converted to Pdf and mailed to them. Help me!!

It’s like I got 4 folders (North, South,East, West) in a path and inside each region’s folder We got a folder named after our customers.

Example: North\Microsoft


Now inside that customers folder we prepare pricing for every month in an excel file.

What I need now is a VBA Code to convert the excel files in these folders and save them to PDF in the same folder.

Kindly help me out with this.


Participant Asked on January 3, 2018 in VBA: Macros.
Add Comment
2 Answer(s)

I did not write this code but I think that it may help you. For more information about this code visit :  http://www.contextures.com/excelvbapdf.html

Sub PDFActiveSheet()
‘for Excel 2010 and later
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler

Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), “yyyymmdd\_hhmm”)

‘get active workbook folder, if saved
strPath = wbA.Path
If strPath = “” Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & “\”

‘replace spaces and periods in sheet name
strName = Replace(wsA.Name, ” “, “”)
strName = Replace(strName, “.”, “_”)

‘create default name for savng file
strFile = strName & “_” & strTime & “.pdf”
strPathFile = strPath & strFile

‘use can enter name and
‘ select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:=”PDF Files (*.pdf), *.pdf”, _
Title:=”Select Folder and FileName to save”)

‘export to PDF if a folder was selected
If myFile <> “False” Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
‘confirmation message with file info
MsgBox “PDF file has been created: ” _
& vbCrLf _
& myFile
End If

Exit Sub
MsgBox “Could not create PDF file”
Resume exitHandler
End Sub

Top Contributor Answered on January 3, 2018.

Thanks!!!! will try it out and let you know

on January 3, 2018.
Add Comment

Please try this as well.

Sub Save2PDF()

Dim Fname As String

Fname = InputBox(“Enter file name to save”, “Save as PDF”)


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Fname, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _

End Sub

Top Contributor Answered on January 3, 2018.
Add Comment
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.