Array input parameter

Shahzadt

Board Regular
Joined
Aug 25, 2009
Messages
72
I am currently using a sub which calls a sub to zip mulitple files in a directory, which uses getopenfilename box to select the files. I have to repeat this mulitple times on daily bases. i was wondering if it is possible to pass a parameters to omit getopenfilename box?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
GetOpenFilename results in a string -- either a fullname or "False". So if you know what the file path and filenames will be, yes, you can automate that part.
 
Upvote 0
all the files to be ziped have the same path; I have the file path saved in a variable and also all files to be ziped have a common partial name i have that saved in a variable as well. is it possible if you could show me an example.
 
Upvote 0
The point here is that we need to build in AI (artificial intelligence) to determine the fullname (the location and file name) instead of asking the user.

1. You have won half the battle by having the file path in your variable. What about the file name? How will you derive that?
2. If you can paste that part of the code where it uses the GetOpenFilename I can explain it better.
 
Upvote 0
I also have part of file name as variable - all files to be ziped start with the same file name string. following is the code sniplet
Code:
'   Get the file names
    FileNames = Application.GetOpenFilename _
         (filefilter:="All Files (*.*),*.*", FilterIndex:=1, _
         Title:="Select the files to ZIP", MultiSelect:=True)
 
'   Exit if dialog box canceled
    If Not IsArray(FileNames) Then Exit Sub
 
    FileCount = UBound(FileNames)
    FileNameZip = Application.DefaultFilePath & "\TEST.zip"
 
    'Create empty Zip File with zip header
    Open FileNameZip For Output As #1
    Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
    Close #1
 
    Set ShellApp = CreateObject("Shell.Application")
 
    'Copy the files to the compressed folder
    For i = LBound(FileNames) To UBound(FileNames)
        ShellApp.Namespace(FileNameZip).CopyHere FileNames(i)
    Next i
 
    'Keep script waiting until Compressing is done
    On Error Resume Next
    Do Until ShellApp.Namespace(FileNameZip).items.Count = FileCount
        Application.Wait (Now + TimeValue("0:00:01"))
    Loop
 
Upvote 0
The following code will zip all the files in the specified folder. You modify further to suit your need.

For convenience i have marked my lines as "new line" and commented the code for the GetOpenFilename.

Code:
Dim strFilename As String                                   'New line
Dim strSourceFolder As String                               'New line
strSourceFolder = "C:\Your Folder Path"                     'New line
strFilename = Dir(strSourceFolder & "\" & "*.*")            'New line
ReDim FileNames(0)                                          'New line
Do While Len(strFilename) > 0                               'New line
 
    If FileNames(0) <> "" Then _
       ReDim Preserve FileNames(UBound(FileNames) + 1)      'New line
    FileNames(UBound(FileNames)) = strFilename              'New line
    strFilename = Dir                                       'New line
Loop                                                        'New line
''   Get the file names
'    FileNames = Application.GetOpenFilename _
'         (filefilter:="All Files (*.*),*.*", FilterIndex:=1, _
'         Title:="Select the files to ZIP", MultiSelect:=True)
'
''   Exit if dialog box canceled
'    If Not IsArray(FileNames) Then Exit Sub
 
    FileCount = UBound(FileNames)
    FileNameZip = Application.DefaultFilePath & "\TEST.zip"
 
    'Create empty Zip File with zip header
    Open FileNameZip For Output As #1
    Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
    Close #1
 
    Set ShellApp = CreateObject("Shell.Application")
 
    'Copy the files to the compressed folder
    For i = LBound(FileNames) To UBound(FileNames)
        ShellApp.Namespace(FileNameZip).CopyHere FileNames(i)
    Next i
 
    'Keep script waiting until Compressing is done
    On Error Resume Next
    Do Until ShellApp.Namespace(FileNameZip).items.Count = FileCount
        Application.Wait (Now + TimeValue("0:00:01"))
    Loop
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top