Hi all!
I feel like this code is VERY close but cannot see the error I'm making
It nearly finishes then the automation error. Feeling like it's something small but cant figure out the solution.
It's supposed to let the user browse to a pdf then compress it with 7Zip. How would you remedy this?
Thanks, in advance, as always!
I feel like this code is VERY close but cannot see the error I'm making
VBA Code:
Sub ZipThis()
Dim src As Variant, dst As Variant, file As Variant
Dim f As String, Path As String, FileType As String
Dim wsh As Object, strCommand As String
Const PATH_TO_7Z = "C:\Program Files\7-Zip\7z.exe"
src = Application.GetOpenFilename(filefilter:="PDF Files (*.pdf), *.pdf", Title:="Select the file you want to zip")
f = src
ary = Split(f, "\")
bry = Split(ary(UBound(ary)), ".")
ary(UBound(ary)) = ""
ThePath = Join(ary, "\")
Filename = bry(0)
FileType = bry(1)
dst = ThePath
Set wsh = CreateObject("WScript.Shell")
strCommand = PATH_TO_7Z & " a -tzip """ & dst & Filename & ".zip"" """ & dst & """"
lngErrorCode = wsh.Run(strCommand, WindowStyle:=1, WaitOnReturn:=1) ' <<<< Automation error. The system cannot find the file specified
MsgBox "Done!"
End Sub
It nearly finishes then the automation error. Feeling like it's something small but cant figure out the solution.
It's supposed to let the user browse to a pdf then compress it with 7Zip. How would you remedy this?
Thanks, in advance, as always!