Apu_Shah
asked on
VBA or VBS to Zip files in a folder - Win XP , Using Access (VBA Code)
I am using Microsoft access on windows XP.
Here is what i want.
VBA code or VBS to
Zip files in a local folder.
Assumptions: Files and folders located locally.
Zip using winzip.
Zip a file from the folder and place the zipped version of the file in the same location with different name.
Let me know, if you have answer to this.
Thanz
Here is what i want.
VBA code or VBS to
Zip files in a local folder.
Assumptions: Files and folders located locally.
Zip using winzip.
Zip a file from the folder and place the zipped version of the file in the same location with different name.
Let me know, if you have answer to this.
Thanz
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
have u chacked PathWinZip = "C:\program files\winzip\" or anything else
:)
:)
ASKER
Yes, its a valid path.
ASKER
.DefaultFilePath
Method or data member not found
Method or data member not found
just checked it out. Works fine. Trying to find out the prob.
ASKER
I am using MS ACCESS 2002.
I am sure i am missing some lib , in reference.
I am sure i am missing some lib , in reference.
That portion of the code is only creating a filepath. That you can build it yourself. Remove
' Build the path and name for the zip file
DefPath = Application.DefaultFilePat h
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If
FileNameZip = DefPath & strDate & ".zip"
and just have
FileNameZip = "C:\WhateverDir\WhateverSu bDir\Whate verFile.zi p"
' Build the path and name for the zip file
DefPath = Application.DefaultFilePat
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If
FileNameZip = DefPath & strDate & ".zip"
and just have
FileNameZip = "C:\WhateverDir\WhateverSu
ASKER
Sub Zip_Folder_And_SubFolders(
Dim PathWinZip As String, FileNameZip As String, FolderName As String
Dim ShellStr As String, strDate As String, DefPath As String
PathWinZip = "C:\program files\winzip\"
'This will check if this is the path where WinZip is installed.
If Dir(PathWinZip & "winzip32.exe") = "" Then
MsgBox "Please find your copy of winzip32.exe and try again"
Exit Sub
End If
FileNameZip = "C:\Documents and Settings\user\Desktop\Desk
'Fill in the folder name
FolderName = "C:\Documents and Settings\user\Desktop\Desk
'Add a slash at the end if the user forget it
If Right(FolderName, 1) <> "\" Then
FolderName = FolderName & "\"
End If
'Zip the folder, -r is Include subfolders, -p is folder information
ShellStr = PathWinZip & "Winzip32 -min -a -r -p" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FolderName & Chr(34)
gives error --> ShellAndWait ShellStr, vbHide
MsgBox "The zipfile is ready in: " & FileNameZip
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sub Zip_Folder_And_SubFolders(
Dim PathWinZip As String, FileNameZip As String, FolderName As String
Dim ShellStr As String, strDate As String, DefPath As String
PathWinZip = "C:\program files\winzip\"
'This will check if this is the path where WinZip is installed.
If Dir(PathWinZip & "winzip32.exe") = "" Then
MsgBox "Please find your copy of winzip32.exe and try again"
Exit Sub
End If
FileNameZip = "C:\Documents and Settings\abc\test.zip"
'Fill in the folder name
FolderName = "C:\Documents and Settings\abc\"
'Add a slash at the end if the user forget it
If Right(FolderName, 1) <> "\" Then
FolderName = FolderName & "\"
End If
'Zip the folder, -r is Include subfolders, -p is folder information
ShellStr = PathWinZip & "Winzip32 -min -a -r -p" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " " & Chr(34) & FolderName & Chr(34)
ShellAndWait ShellStr, vbHide
MsgBox "The zipfile is ready in: " & FileNameZip
End Sub
Public Sub ShellAndWait(PathName As String)
Dim TaskID As Double
'Run application and return Process ID (TaskID)
TaskID = Shell(PathName, vbHide) ', vbNormalFocus)
While TaskExists(TaskID)
'Wait for TaskExists False
Wend
End Sub
Gives error : wrong number of arguments or invalid property.
Help...
You did not change
ShellAndWait ShellStr, vbHide
to
ShellAndWait ShellStr
ShellAndWait ShellStr, vbHide
to
ShellAndWait ShellStr
ASKER
sub or function not defined.
TaskExists
TaskExists
Add ...
Public Function TaskExists(TaskID As Double) As Boolean
'Raise Error if TaskID does not exist
On Error GoTo ErrorHandler
'Attempt to activate TaskID
AppActivate (TaskID)
'If AppActivate returns an error, we know that the
'process is finished. We handle the error and return
'the function as false--this allows the calling
'procedure to exit the While loop.
ErrorHandler: If Err.Number = 5 Then
TaskExists = False
Exit Function
Else
TaskExists = True
End If
End Function
http://experts.about.com/q/Using-MS-Access-1440/Link-tables-Schema-ini.htm
Public Function TaskExists(TaskID As Double) As Boolean
'Raise Error if TaskID does not exist
On Error GoTo ErrorHandler
'Attempt to activate TaskID
AppActivate (TaskID)
'If AppActivate returns an error, we know that the
'process is finished. We handle the error and return
'the function as false--this allows the calling
'procedure to exit the While loop.
ErrorHandler: If Err.Number = 5 Then
TaskExists = False
Exit Function
Else
TaskExists = True
End If
End Function
http://experts.about.com/q/Using-MS-Access-1440/Link-tables-Schema-ini.htm
ASKER
Thank you , it worked.
ASKER
Application.DefaultFilePat
I think i am missing some Lib.
Let me know,
Thanz