Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA CopyHere is copying folders only - not files

Status
Not open for further replies.

ITGzr

Technical User
Jan 17, 2012
3
US
Hi. I'm using CopyHere in MS Access 2007 to copy and unzip files from a compressed folder (OS=Win XP Pro SP2).

The problem is that it is copying the whole folder but not the individual files within.

Is there some type of parameter that can instruct CopyHere to copy just files from the compressed folder?

Thanks for any assistance you can provide.
 
Here is a little code that will open a zip file including self executables and unzip the contents to where you want.

The Shell and wait function is used to pause access so winzip can finish and close before access does anything else.

Code:
Option Compare Database
Option Explicit

Declare Function OpenProcess Lib "kernel32" _
                             (ByVal dwDesiredAccess As Long, _
                              ByVal bInheritHandle As Long, _
                              ByVal dwProcessId As Long) As Long

Declare Function GetExitCodeProcess Lib "kernel32" _
                                    (ByVal hProcess As Long, _
                                     lpExitCode As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STILL_ACTIVE = &H103


Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
    On Error GoTo xxx
    Dim hProg As Long
    Dim hProcess As Long, ExitCode As Long
    'fill in the missing parameter and execute the program
    If IsMissing(WindowState) Then WindowState = 1
    hProg = Shell(PathName, WindowState)
    'hProg is a "process ID under Win32. To get the process handle:
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
    Do
        'populate Exitcode variable
        GetExitCodeProcess hProcess, ExitCode
        DoEvents
    Loop While ExitCode = STILL_ACTIVE
    Exit Sub

xxx:
    MsgBox "Unexpected error - " & Err.Number & vbCrLf & _
           vbCrLf & Error$, vbExclamation, "Modules - ShellAndWait"
    Exit Sub
End Sub

Function fcnUnZipZipFile()

    Dim PathZipProgram As String, NameUnZipFolder As String
    Dim FileNameZip As Variant
    Dim ShellStr As String, Password As String
    Dim strFileLocation As String, strDaily As String
    

    PathZipProgram = "C:\program files\winzip"
    If Right(PathZipProgram, 1) <> "\" Then
        PathZipProgram = PathZipProgram & "\"
    End If
    'Check if this is the path where WinZip is installed.

    If Dir(PathZipProgram & "winzip32.exe") = "" Then
        MsgBox "Please find your copy of winzip32.exe and try again"
        Exit Function
    End If

    
    strFileLocation = "C:\Filenamehere"
    
    NameUnZipFolder = "C:\FoldertoUnzipTo"""
    FileNameZip = strFileLocation
    

    ShellStr = PathZipProgram & "Winzip32.exe -min -e -o" _
                  & " " & Chr(34) & FileNameZip & Chr(34) _
                  & " " & Chr(34) & NameUnZipFolder & Chr(34)
    ShellAndWait ShellStr, vbHide

End Function

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
Dim intOptions, objItem
Dim objShell
Set objShell = CreateObject("Shell.Application")
intOptions = 256
Set objSource = objShell.NameSpace(FileNameFolderZip).Items()
Set objTarget = objShell.NameSpace(FileNameFolder)
objTarget.CopyHere objSource, intOptions
 
Thanks for your reply. This is really great but my client does not allow third party software at their site so I had to rely on the compressed folder unzip feature built into Win XP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top