How to add a file picker to this macro.

thardin

Board Regular
Joined
Sep 29, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
I have code that runs a report for work. It starts with finding the workbook to activate and then run the report on that wb. This method works most of the time, but I just realized that there are WAY too many workbook name possibilities for this method to be dependable everyday and the name is constantly changing.

How do I add a "file picker" so as soon as I click on the userform button it requires you to select a file to run the report on?

BTW, I have a variable called My_downloads that I would like the file to be picked from

Thanks.


VBA Code:
Private Sub CommandButton27_Click()
    CommandButton27.BackColor = RGB(0, 100, 0)
     Dim My_Workbook As Workbook
     Dim wb As Workbook
     Dim df As Folder

     Dim FileName As String, FileName2, FileName3, FileName4, F1, F2, F3, F4 As String
     Dim WBFound As Boolean
     FileName = FullDate & "ED Restrictions Voids*.xlsx"
     FileName2 = FullDate & " EDRestrictions Voids*.xlsx"
     FileName3 = FullDate3 & "ED  A Share Restrictions Voids*.xlsx"
     FileName4 = FullDate3 & " ED  A Share Restrictions Voids*.xlsx"
  
  
'***********************************************************
' Find and activate workbook file to activate and run macro
'   - look in open workbooks and downloads folder
'***********************************************************
    WBFound = False
  
    For Each wb In Application.Workbooks
            If wb.Name Like FileName Or wb.Name Like FileName2 Or _
                wb.Name Like FileName3 Or wb.Name Like FileName4 Then
                WBFound = True
                wb.Activate
                Call UBT_Combo_P1
                CommandButton27.Enabled = False
  
            End If
    Next wb
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Glad to hear you figured it out.

If you would like to post the solution then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,739
Members
449,050
Latest member
excelknuckles

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