[RESOLVED] dim "blah" as Shell32 problem?
got this code from codebank i got the create_empty_zip working excellent but when i get to zip a folder or file i get error on
vb Code:
Private Sub Zip_Activity(Action As String, sFileSource As String, sFileDest As String)
'//copies contents of folder to zip file
Dim ShellClass As Shell32.Shell 'I GET ERROR HERE it doesnt exist in my list
Dim Filesource As Shell32.Folder 'error
Dim Filedest As Shell32.Folder 'error
Dim Folderitems As Shell32.Folderitems 'errors
If sFileSource = "" Or sFileDest = "" Then GoTo EH
Select Case UCase$(Action)
Case "ZIPFILE"
If Right$(UCase$(sFileDest), 4) <> ".ZIP" Then
sFileDest = sFileDest & ".ZIP"
End If
If Not Create_Empty_Zip(sFileDest) Then
GoTo EH
End If
Set ShellClass = New Shell32.Shell
Set Filedest = ShellClass.NameSpace(sFileDest)
Call Filedest.CopyHere(sFileSource, 20)
Case "ZIPFOLDER"
If Right$(UCase$(sFileDest), 4) <> ".ZIP" Then
sFileDest = sFileDest & ".ZIP"
End If
If Not Create_Empty_Zip(sFileDest) Then
GoTo EH
End If
'//Copy a folder and its contents into the newly created zip file
Set ShellClass = New Shell32.Shell
Set Filesource = ShellClass.NameSpace(sFileSource)
Set Filedest = ShellClass.NameSpace(sFileDest)
Set Folderitems = Filesource.Items
Call Filedest.CopyHere(Folderitems, 20)
Case "UNZIP"
If Right$(UCase$(sFileSource), 4) <> ".ZIP" Then
sFileSource = sFileSource & ".ZIP"
End If
Set ShellClass = New Shell32.Shell
Set Filesource = ShellClass.NameSpace(sFileSource) '//should be zip file
Set Filedest = ShellClass.NameSpace(sFileDest) '//should be directory
Set Folderitems = Filesource.Items '//copy zipped items to directory
Call Filedest.CopyHere(Folderitems, 20)
Case Else
End Select
'//Ziping a file using the Windows Shell API creates another thread where the zipping is executed.
'//This means that it is possible that this console app would end before the zipping thread
'//starts to execute which would cause the zip to never occur and you will end up with just
'//an empty zip file. So wait a second and give the zipping thread time to get started.
Call Sleep(1000)
EH:
If Err.Number <> 0 Then
MsgBox Err.Description, vbExclamation, "error"
End If
Set ShellClass = Nothing
Set Filesource = Nothing
Set Filedest = Nothing
Set Folderitems = Nothing
End Sub
how come i do not have the Shell32 option to dim as?
is it normal that i do not have it or do i have to install something or i can dim it a different way? i need some advice/help
thanks in advance
Re: dim "blah" as Shell32 problem?
add a reference to shell automation?
Quote:
or i can dim it a different way?
you can use latebinding and declare all as objects
Re: dim "blah" as Shell32 problem?