Execute macro from droplist

greegan

Well-known Member
Joined
Nov 18, 2009
Messages
643
Office Version
  1. 365
Platform
  1. Windows
I have
Code:
    Dim wbNames As Range:           Set wbNames = Range("GroupList[GroupX]")
in my declarations(?) where GroupList is a table of 6 columns numbered 1-5 and X for the 6th one.
GroupX for this example is the column selected. With the following code,

Code:
Dim wb As Workbook
Dim strCPF As String
Dim wbNames As Range:           Set wbNames = Range("GroupList[GroupX]")
Dim rngGroupList As Range
Application.DisplayAlerts = False
    strCPF = "P" & Company.Function & " Accounts"

    On Error Resume Next ' Work
        For Each rngGroupList In wbNames
            Set wb = Workbooks.Open("W:\Directory\" & Format(Now(), "yyyy") & _
                "\CompanyFolder\" & strCPF & "\" & rngGroupList & ".xlsx")
                    If Not wb Is Nothing Then
                        Call b2_OpenDataFile
                        
                    wb.Close False '
                    Set wb = Nothing '
                    End If
            ActiveWorkbook.Save
        Next rngGroupList
    Sheets("DATA").Select

the macro will open all files(named) in the column specified.
I also have six files, Group1-Group5 and GroupX. All files will have the same macros. I would like
Code:
    Dim wbNames As Range:           Set wbNames = Range("GroupList[GroupX]")
to do one of two things:
either have a droplist showing the headers of each column, once selected and OK or Continue or whatever button is available, execute the macro specifically for that workbook... OR...
have the code read the name of the active workbook (Which could have something before or after "Group#" such as "Check GroupX.xlsm" or GroupX Check File.xlsm" and automatically look for that column and execute the macro.

So I need either a droplist to allow the macros be compatible with each file or somehow read the file name (the Group# part) and determine which table column to look at.

Thank you for any assistance provided.

-- g
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
How about I update this question with this?
If my file name is Accounts-Group X-Date_Time.xlsm
How would I grab Group X and use it in the
Code:
    Dim wbNames As Range:           Set wbNames = Range("GroupList[Group X]")
Code given in my earlier post?
If I can make this happen then I shouldn't need a drop list.

-- g
 
Upvote 0
was it just a bad choice for the subject? I'm hoping someone can help me here?

-- g
 
Upvote 0

Forum statistics

Threads
1,216,129
Messages
6,129,047
Members
449,482
Latest member
al mugheen

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