Macro to create PDF

  • Thread starter Thread starter gotahavit
  • Start date Start date
G

gotahavit

I have a macro that creates PDFs. Within the macro, I identify the active
printer: ActivePrinter:="Adobe PDF on Ne01:". I got this from recording a
macro. Well, when others try to use it, the Ne01 is different. For some it is
Ne03 and others Ne02. When those people run the macro it still creates a PDF,
but the font gets messed up.
Is there a way (within the macro) to identify a list of the available
printers, or the Ne# for the particular computer, or is there any other way
to go around the issue?

Thanks.
 
Hi gotahavit

The Ne number of a printer can be different for every user
You can try this to print to for example the Adobe PDF printer


Sub Test()
Dim str As String
Dim strNetworkPrinter As String
str = Application.ActivePrinter

strNetworkPrinter = GetFullNetworkPrinterName("Adobe PDF")
If Len(strNetworkPrinter) > 0 Then
Application.ActivePrinter = strNetworkPrinter
ActiveSheet.PrintOut
End If

Application.ActivePrinter = str
End Sub


Function GetFullNetworkPrinterName(strNetworkPrinterName As String) As String
Dim strCurrentPrinterName As String, strTempPrinterName As String, i As Long
strCurrentPrinterName = Application.ActivePrinter
i = 0
Do While i < 100
strTempPrinterName = strNetworkPrinterName & " on Ne" & Format(i, "00") & ":"
On Error Resume Next ' try to change to the network printer
Application.ActivePrinter = strTempPrinterName
On Error GoTo 0
If Application.ActivePrinter = strTempPrinterName Then
GetFullNetworkPrinterName = strTempPrinterName
i = 100 ' makes the loop end
End If
i = i + 1
Loop
Application.ActivePrinter = strCurrentPrinterName ' change back to the original printer
End Function
 
Thanks. It worked.

Ron de Bruin said:
Hi gotahavit

The Ne number of a printer can be different for every user
You can try this to print to for example the Adobe PDF printer


Sub Test()
Dim str As String
Dim strNetworkPrinter As String
str = Application.ActivePrinter

strNetworkPrinter = GetFullNetworkPrinterName("Adobe PDF")
If Len(strNetworkPrinter) > 0 Then
Application.ActivePrinter = strNetworkPrinter
ActiveSheet.PrintOut
End If

Application.ActivePrinter = str
End Sub


Function GetFullNetworkPrinterName(strNetworkPrinterName As String) As String
Dim strCurrentPrinterName As String, strTempPrinterName As String, i As Long
strCurrentPrinterName = Application.ActivePrinter
i = 0
Do While i < 100
strTempPrinterName = strNetworkPrinterName & " on Ne" & Format(i, "00") & ":"
On Error Resume Next ' try to change to the network printer
Application.ActivePrinter = strTempPrinterName
On Error GoTo 0
If Application.ActivePrinter = strTempPrinterName Then
GetFullNetworkPrinterName = strTempPrinterName
i = 100 ' makes the loop end
End If
i = i + 1
Loop
Application.ActivePrinter = strCurrentPrinterName ' change back to the original printer
End Function
 
Hi Ron.
I am succesfully using your RDB_Create_PDF function for creating PDF's
(thank you!)
Is there a way to make the PDFs password protected?
Thanks in advance,
Albert C.
 
Back
Top