Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50243

Convert to PDF Macro - Tweek needed

$
0
0
Hey,

Im trying to add a macro to sheet1 that automatically converts to a pdf.
I've used the following, but it converts all the other sheets as well. How can I make it so only Sheet1 converts and not the entire workbook?

Option Explicit

Sub ExcelToPDF()

Dim iPtr As Long
Dim sFileName As String

iPtr = InStrRev(ActiveWorkbook.FullName, ".")

If iPtr = 0 Then
sFileName = ActiveWorkbook.FullName & ".pdf"
Else
sFileName = Left(ActiveWorkbook.FullName, iPtr - 1) & ".pdf"
End If

sFileName = Application.GetSaveAsFilename(InitialFileName:=sFileName, FileFilter:="PDF Files (*.pdf), *.pdf")

If sFileName = "False" Then Exit Sub

ThisWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFileName, Quality:=xlQualityStandard, openAfterPublish:=True

End Sub

Viewing all articles
Browse latest Browse all 50243

Trending Articles