bmjones1013
New Member
I'm new to creating codes and macros. What I'm looking to do is create a template that allows our managers to fill in a few pieces of information on my DATA tab that will feed into the other tabs. Then they will click on the sheet names they want to save as one pdf by clicking these sheet names in a list box. Then to save as one PDF, I'm trying to create a code so when the click on the form control button, the code/macro runs and pops up a save as dialog box with PDF already selected as the file type, and they can save it anywhere of their choosing. After lots of searching, I was able to create the code below. For the most part it works, except no matter which sheets I choose from my list box it prints all sheets in the workbook. Please help me find and fix my mistake.
>>> use code - tags <<<
>>> use code - tags <<<
Code:
Sub Save_Workbook_As_PDF()
Dim i As Long, c As Long
Dim SheetArray() As String
With ActiveSheet.ListBoxSh
For i = 0 To .ListCount - 1
If .Selected(i) Then
ReDim Preserve SheetArray(c)
SheetArray(c) = .List(i)
c = c + 1
End If
Next i
End With
With Application.FileDialog(msoFileDialogSaveAs)
PDFindex = 0
For i = 1 To .Filters.Count
If InStr(VBA.UCase(.Filters(i).Description), "PDF") > 0 Then PDFindex = i
Next
.Title = "Save workbook as PDF"
.InitialFileName = PDFfileName
.FilterIndex = PDFindex
If .Show Then
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=.SelectedItems(1), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End If
End With
End Sub
Last edited by a moderator: