Macro for all Excel Workbooks to print to PDF

Giganews Newsgroups
Subject: Macro for all Excel Workbooks to print to PDF
Posted by:  Robin Coe (robinsc…@gmail.com)
Date: Fri, 16 May 2014

I found the following macro which prints all selected sheets in an Excel wo=
rkbook into multiple PDFs and names them the Excel Worksheet name. The firs=
t test I did it worked perfectly and saved the PDFs in the same folder that=
the Excel workbook was in, which was a folder on my desktop.  I then put t=
he macro in a personal.xls in C:\ProgramFiles\MicrosoftOffice\OFFICE12\XLSt=
art and tried a different Excel workbook in a different location.  The macr=
o was viewable and allowed me to run it, however, it doesn't appear to have=
saved the PDFs.  Can someone tell me what I need to change in my code?

Sub Macro1()
    Dim N As Long
    Dim fileString As String
    Dim cellValue As String
  =20
    With ActiveWindow.SelectedSheets
        For N =3D 1 To .Count
            Sheets(.Item(N).Name).Select
            cellValue =3D Trim(Sheets(.Item(N).Name).Range("A1").Value)
            fileString =3D .Item(N).Name & cellValue & ".pdf"
            Sheets(.Item(N).Name).ExportAsFixedFormat Type:=3DxlTypePDF, Fi=
lename:=3DfileString
        Next N
    End With

End Sub

Replies