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