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'
the error high lights the bold code
why and how to fix it??
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??