www rondebruin nl win s7 win002

Upload: jhdmss

Post on 03-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Www Rondebruin Nl Win s7 Win002

    1/4

  • 8/11/2019 Www Rondebruin Nl Win s7 Win002

    2/4

    Set oApp = CreateObject("Shell.Appl ication")

    oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).items

    'If you want to extract only one file you can use this:

    'oApp.Namespace(FileNameFolder).CopyHere _

    'oApp.Namespace(Fname).items.Item("test.txt")

    MsgBox "You find the files here: " & FileNameFolder

    On Error Resume Next

    Set FSO = CreateObject("scripting.filesystemobject")

    FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True

    End If

    End Sub

    Example 2

    The macro below is almost the same as above. The only difference is that it will only extract txt files from the Zip file. Change

    this "*.txt" to extract the files you want. If you want to extract one file from a Zip file see the commented code in the macro

    above.

    Sub Unzip2() Dim FSO As Object

    Dim oApp As Object

    Dim Fname As Variant

    Dim FileNameFolder As Variant

    Dim DefPath As String

    Dim strDate As String

    Dim fileNameInZip As Variant

    Fname = Application.GetOpenFilename(filefil ter:="Zip Files (*.zip), *.zip", _

    MultiSelect:=False)

    If Fname = False Then

    'Do nothing

    Else

    'Root folder for the new folder.

    'You can also use DefPath = "C:\Users\Ron\test\"

    DefPath = Application.DefaultFilePath

    If Right(DefPath, 1) "\" Then

    DefPath = DefPath & "\"

    End If

    'Create the folder name

    strDate = Format(Now, " dd-mm-yy h-mm-ss")

    FileNameFolder = DefPath & "MyUnzipFolder " & strDate & "\"

    'Make the normal folder in DefPath

    MkDir FileNameFolder

    'Extract the files into the newly created folder

    Set oApp = CreateObject("Shell.Appl ication")

    'Change this "*.txt" to extract the files you want

    For Each fileNameInZip In oApp.Namespace(Fname).items

    If LCase(fileNameInZip) Like LCase("*.txt") Then

    oApp.Namespace(FileNameFolder).CopyHere _

    oApp.Namespace(Fname).items.Item(CStr(fileNameInZip))

    End If

    Next

    MsgBox "You find the files here: " & FileNameFolder

    On Error Resume Next Set FSO = CreateObject("scripting.filesystemobject")

    FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True

    End If

    End Sub

  • 8/11/2019 Www Rondebruin Nl Win s7 Win002

    3/4

    Example 3

    The macros above will create a new folder for you to copy the files in. But this macro unzip the zip file in a fixed folder

    "C:\Users\Ron\test\". See the commented code in the macro to delete the files in the folder first if you want.

    Sub Unzip3()

    Dim FSO As Object

    Dim oApp As Object

    Dim Fname As Variant

    Dim FileNameFolder As Variant

    Dim DefPath As String

    Fname = Application.GetOpenFilename(filefil ter:="Zip Files (*.zip), *.zip", _

    MultiSelect:=False)

    If Fname = False Then

    'Do nothing

    Else

    'Destination folder

    DefPath = "C:\Users\Ron\test\" '

  • 8/11/2019 Www Rondebruin Nl Win s7 Win002

    4/4

    strDate = Format(Now, " dd-mm-yy h-mm-ss")

    FileNameFolder = DefPath & "MyUnzipFolder " & strDate & "\"

    'Make the normal folder in DefPath

    MkDir FileNameFolder

    'Extract the files into the newly created folder

    Set oApp = CreateObject("Shell.Appl ication")

    For I = LBound(Fname) To UBound(Fname)

    num = oApp.Namespace(FileNameFolder).items.Count

    oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname(I)).items

    Next I

    MsgBox "You find the files here: " & FileNameFolder

    On Error Resume Next

    Set FSO = CreateObject("scripting.filesystemobject")

    FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True

    End If

    End Sub

    Copyright 2013 Ron de Bruin

    Site designed by Spider Web Woman Designs

    http://www.spiderwebwoman.com/