View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Robin Coe Robin Coe is offline
external usenet poster
 
Posts: 3
Default Macro for all Excel Workbooks to print to PDF

I found the following macro which prints all selected sheets in an Excel workbook into multiple PDFs and names them the Excel Worksheet name. The first 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 the macro in a personal.xls in C:\ProgramFiles\MicrosoftOffice\OFFICE12\XLStart and tried a different Excel workbook in a different location. The macro 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

With ActiveWindow.SelectedSheets
For N = 1 To .Count
Sheets(.Item(N).Name).Select
cellValue = Trim(Sheets(.Item(N).Name).Range("A1").Value)
fileString = .Item(N).Name & cellValue & ".pdf"
Sheets(.Item(N).Name).ExportAsFixedFormat Type:=xlTypePDF, Filename:=fileString
Next N
End With

End Sub