Generate pdf Run Time Error 13

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I am currently using the code below to generate a pdf & works fine.

On my worksheet i have a values in the cells shown & this is how i would like the pdf to be named.
Currently the code specifies ("E5") cell only so the pdf is saved / named as A.pdf

I have changed ("E5") to ("E5;J5") hoping to save / name the file as EFGHIL.pdf but then i see the RTE 13

Example of values in cells
E5 A
F5 B
G5 C
H5 D
I5 E
J5 F

Can you advise what is incorrect Thanks

Rich (BB code):
Private Sub EbayPdf_Click()
  Dim sPath As String, strFileName As String
  
  strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\EBAY PDF\" & Range("E5").Value & ".pdf"
     With ActiveSheet
    If Range("E5") = "" Then
    MsgBox "NO CODE SHOWN TO GENERATE PDF", vbCritical, "NO CODE ON SHEET TO CREATE PDF"
    Exit Sub
    End If
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
  MsgBox "PDF HAS NOW BEEN GENERATED", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE"
  
  End With
  
  sPath = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR SCREEN SHOT PDF\"
  strFileName = sPath & Range("E5").Value & ".pdf"
  If Dir(strFileName) <> vbNullString Then
    ActiveWorkbook.FollowHyperlink strFileName
  End If

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi Ian,

maybe

VBA Code:
Private Sub EbayPdf_Click()
Dim sPath As String, strFileName As String

Const cstrDISCOII As String = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\EBAY PDF\"
Const cstrPATH As String = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR SCREEN SHOT PDF\"

With ActiveSheet
  If Range("E5") = "" Then
    MsgBox "NO CODE SHOWN TO GENERATE PDF", vbCritical, "NO CODE ON SHEET TO CREATE PDF"
    Exit Sub
  End If
  strFileName = WorksheetFunction.TextJoin("", True, .Range("E5:J5")) & ".pdf"
  .ExportAsFixedFormat Type:=xlTypePDF, _
                        Filename:=cstrDISCOII & strFileName, _
                        Quality:=xlQualityStandard, _
                        IncludeDocProperties:=True, _
                        IgnorePrintAreas:=False, _
                        OpenAfterPublish:=False
  MsgBox "PDF HAS NOW BEEN GENERATED", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE"

End With

'pdf has been created in different folder so I would expect something like
'strFileName = cstrDISCOII & strFileName

strFileName = cstrPATH & strFileName
If Dir(strFileName) <> vbNullString Then
  ActiveWorkbook.FollowHyperlink strFileName
End If

End Sub

I saw that you save the pdf into one folder but the hyperlink leads to a different one. If it*s the same folder for both actions strFileName may be filled with the path as well, be applicated to save and would not have to be filled again to follow the hyperlink.

Holger
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top