Hey all -
I am trying to write a macro that will print a worksheet to PDF and automaically name the file. This is the code I have so far:
Option Explicit
Private Sub PrintToPDF_Click()
Dim CurrentPrinter As String
Dim fileName As String
Let fileName = Cells(7, "e")
'Sets the sheet to print out in black and white
ActiveSheet.PageSetup.BlackAndWhite = True
CurrentPrinter = Application.ActivePrinter ' save the currently active printer
On Error Resume Next ' ignore errors
Application.ActivePrinter = "Adobe PDF on Ne05:" ' change to PDF printer
SendKeys fileName & "{ENTER}" ', False
ActiveSheet.PrintOut ' print the active sheet (Network Funding)
Application.ActivePrinter = CurrentPrinter ' change back to the original printer
On Error GoTo 0 ' resume normal error handling
End Sub
The problem is the sendkeys function does nothing and I still have to manually input the file name. Can anyone please help?!?!
Thanks -
Cara
I am trying to write a macro that will print a worksheet to PDF and automaically name the file. This is the code I have so far:
Option Explicit
Private Sub PrintToPDF_Click()
Dim CurrentPrinter As String
Dim fileName As String
Let fileName = Cells(7, "e")
'Sets the sheet to print out in black and white
ActiveSheet.PageSetup.BlackAndWhite = True
CurrentPrinter = Application.ActivePrinter ' save the currently active printer
On Error Resume Next ' ignore errors
Application.ActivePrinter = "Adobe PDF on Ne05:" ' change to PDF printer
SendKeys fileName & "{ENTER}" ', False
ActiveSheet.PrintOut ' print the active sheet (Network Funding)
Application.ActivePrinter = CurrentPrinter ' change back to the original printer
On Error GoTo 0 ' resume normal error handling
End Sub
The problem is the sendkeys function does nothing and I still have to manually input the file name. Can anyone please help?!?!
Thanks -
Cara