I have been using the following code that I snagged here awhile back. Just switched from Excel 2003 to Excel 2007 and now the code is only saving things as the original file name and not the one I have designated in:
ActiveSheet.Range("InvNbr").Value & ".pdf"
Not sure if this line is correct or if the following line needs to be adjusted.
SendKeys Filename & "{ENTER}", False
[h=2]<H2 class="title icon">Original thread from 2008
If you don't have Acrobat Pro and are using a free version of PDF conversion software, try the following (it has been tested on Excel 2003 and CutePDF):
' This line of code calls your PDF printer and runs the conversion. Record your own macro to call your PDF printer and copy and paste it here.
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer on CPW2:", Collate:=True
' This set of code tells the macro to pause for 2 seconds. This will allow for the PDF printer to run through its process and prompt you for a filename.
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
' This line of code specifies your directory as well as the cell or range which you want the filename to come from.
Filename = "C:\Folder1\SubFolder1\" & ActiveSheet.Range("InvNbr").Value & ".pdf"
' This line of code sends the filename characters and the ENTER key to the active application (i.e. the prompt window). The "False" statement allows the macro to continue running without waiting for the keys to be processed.
SendKeys Filename & "{ENTER}", False
</H2>[/h]
ActiveSheet.Range("InvNbr").Value & ".pdf"
Not sure if this line is correct or if the following line needs to be adjusted.
SendKeys Filename & "{ENTER}", False
[h=2]<H2 class="title icon">Original thread from 2008
If you don't have Acrobat Pro and are using a free version of PDF conversion software, try the following (it has been tested on Excel 2003 and CutePDF):
' This line of code calls your PDF printer and runs the conversion. Record your own macro to call your PDF printer and copy and paste it here.
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer on CPW2:", Collate:=True
' This set of code tells the macro to pause for 2 seconds. This will allow for the PDF printer to run through its process and prompt you for a filename.
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
' This line of code specifies your directory as well as the cell or range which you want the filename to come from.
Filename = "C:\Folder1\SubFolder1\" & ActiveSheet.Range("InvNbr").Value & ".pdf"
' This line of code sends the filename characters and the ENTER key to the active application (i.e. the prompt window). The "False" statement allows the macro to continue running without waiting for the keys to be processed.
SendKeys Filename & "{ENTER}", False
</H2>[/h]