+ Reply to Thread
Results 1 to 2 of 2

Open files choosing path in combobox and files in checkbox (user form)

Hybrid View

  1. #1
    Registered User
    Join Date
    03-31-2020
    Location
    Germany
    MS-Off Ver
    2010
    Posts
    7

    Open files choosing path in combobox and files in checkbox (user form)

    Hello all,

    PLease help me with the following problem. I have initial constant path "C:\Users\User1\Desktop\My files" having subfolders 2018, 2019, 2020 , each of them containing subfolders with week 01, 02, 03.

    1) I need to find necessary folder on path consisting of "constant path + sub folder year + subfolder week" by choosing them in combobox (combobox1 - year, combobox2 - week)

    2) in the found folder i need to open .xlsx files starting with letters A, B or C chosen by checkboxes.

    Please help me to complete the code. Thank you so much!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: Open files choosing path in combobox and files in checkbox (user form)

    To get to the folder you need, simply replace your existing .InitialFileName = ...line in CommandButton1_Click() with this:
    .InitialFileName = "C:\Users\ra00036337\Desktop\My files" & "\" & Me.ComboBox1.Value & "\" & Me.ComboBox3.Value
    As for the filename starting with A, B, or C... I presume you don't want user to select more than one, so it would be better to use grouped radio buttons for this (see attached workbook).
    Private Sub CommandButton1_Click()
    Dim sFolder As String
    Dim initial As String
    Dim initial_path As String
    
    ' loop through the radio buttons until we've found the one that's selected
    For Each i In Me.Frame3.Controls
        Debug.Print TypeName(i)
        If TypeName(i) = "OptionButton" Then
            If i.Value Then
                initial = i.Caption
                Exit For
            End If
        End If
    Next i
    
    ' check for completion:
    If Me.ComboBox1.Value = "" Then MsgBox "Please complete all inputs": Exit Sub
    If Me.ComboBox3.Value = "" Then MsgBox "Please complete all inputs": Exit Sub
    If initial = "" Then MsgBox "Please complete all inputs": Exit Sub
    
    ' now check initial path exists:
    initial_path = "C:\Users\ra00036337\Desktop\My files" & "\" & Me.ComboBox1.Value & "\" & Me.ComboBox3.Value & "\"
    If Dir(initial_path, vbDirectory) = "" Then MsgBox "Directory not found": Exit Sub
    
    
     With Application.FileDialog(msoFileDialogFilePicker)
        .Filters.Clear
        .Filters.Add "Excel files", "*.xls*"
        ' excel won't accept a filter like "C*.xlsx", so include the initial in the filename instead:
        .InitialFileName = initial_path & initial & "*"
        If .Show = False Then Exit Sub
        sFolder = .SelectedItems(1)
     End With
     
    End Sub
    Your use of userform1 is obviously incomplete, so I've left it at that.

    Does this help?
    Tim
    Attached Files Attached Files
    Never stop learning!
    <--- please consider *-ing !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA code to open some pdf files and rename it in a different path
    By Frank_smera in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2018, 11:23 AM
  2. Using a ComboBox to Open Word Files
    By jorgeflores in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-05-2018, 12:09 PM
  3. [SOLVED] Open multiple PDF files from certain path
    By amoxia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2013, 07:36 PM
  4. Trying to Open Files Not Located in Specified Path
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2013, 12:40 AM
  5. [SOLVED] VBA - User prompt to determine path to files
    By michaelisk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-08-2013, 05:03 PM
  6. [SOLVED] VBA - Open Excel Files with file path from Named Ranges
    By bbg22 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-06-2012, 11:41 PM
  7. How to set GetOpenfile dialog start path to current open files path.
    By Michael Wise in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2010, 02:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1