XLS to PDF problem

thunder_anger

Board Regular
Joined
Sep 27, 2009
Messages
206
Hi all

i found this thread http://www.mrexcel.com/forum/showthread.php?t=535944&page=3and found that thing interesting but when applying the code below it returns "Run-Time error '5'

Rich (BB code):
Sub WbToPdfToZip()
  
  ' --> Settings, change to suit
  Const PdfName$ = "Test.pdf"
  Const ZipFullName$ = "D:\Test.zip"
  ' <-- End of settings
  
  Dim PdfTempName$
  PdfTempName = Environ("Temp") & "\" & PdfName
  If Len(Dir(PdfTempName)) Then Kill PdfTempName
  ActiveWorkbook.ExportAsFixedFormat xlTypePDF, PdfTempName, xlQualityStandard, True, False, OpenAfterPublish:=False
  Zip ZipFullName, PdfTempName
  If Len(Dir(PdfTempName)) Then Kill PdfTempName

End Sub

' ZVI: Copy Files to ZipFullName archive
Sub Zip(ZipFullName, ParamArray Files())
  Dim FileNumber%, ZipFile$, i&, x
  ' Add ZIP extentions if not set
  ZipFile = Trim(ZipFullName)
  If LCase(Right(ZipFile, 4)) <> ".zip" Then ZipFile = ZipFile & ".zip"
  ' Create an empty zip archive if not already present
  If Len(Dir(ZipFile)) = 0 Then
    FileNumber = FreeFile
    Open ZipFile For Output As #FileNumber
    Print #FileNumber, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
    Close #FileNumber
  End If
  ' Copy files to archive
  With CreateObject("Shell.Application").Namespace((ZipFile))
    For Each x In Files
      .CopyHere (x)
    Next
    Do Until .Items.Count = UBound(Files) + 1
      DoEvents
    Loop
  End With
End Sub

the error high lights the bold code
why and how to fix it??
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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