Ok so I have found a very useful bit of code from another post on here
http://www.mrexcel.com/forum/showthread.php?p=2693297#post2693297
and I am trying to modify it to work for my purposes. The code in question creates a user form that has a combo box that will list all open workbooks and ask you to select one. Now I have modified the code a bit to change the variable name and to make it a list box rather than a combo box. And now my code looks like this.
In the User Form Module I have this
In the actual Module for the macro I am making/testing I have this:
Now what I want to happen is have it ask me which workbook I want to use and then what ever workbook I choose I want that to be the active workbook so I can then start selecting ranges and have the macro pull data from the selected workbook and put it on the one the macro was run in.
My issue is every month we get files with new names so I am trying to avoid having to change the hard coded names for the workbooks each month.
Again any help is appreciated. Thanks.
http://www.mrexcel.com/forum/showthread.php?p=2693297#post2693297
and I am trying to modify it to work for my purposes. The code in question creates a user form that has a combo box that will list all open workbooks and ask you to select one. Now I have modified the code a bit to change the variable name and to make it a list box rather than a combo box. And now my code looks like this.
In the User Form Module I have this
Code:
Option Explicit
Private Sub CommandButton1_Click()
Coastal1 = Me.ListBox1.Value
Unload Me
End Sub
Private Sub CommandButton2_Click()
Stopped = True
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim wkb As Workbook
Me.Label1.Caption = "Please select one of the following files..."
With Me.ListBox1
For Each wkb In Application.Workbooks
.AddItem wkb.Name
Next wkb
End With
End Sub
In the actual Module for the macro I am making/testing I have this:
Code:
Option Explicit
Public Coastal1 As String
Public Stopped As Boolean
Sub test()
Stopped = False
UserForm1.Show
If Stopped Then Exit Sub
Windows("Coastal1 & .xlsm").Activate
End Sub
Now what I want to happen is have it ask me which workbook I want to use and then what ever workbook I choose I want that to be the active workbook so I can then start selecting ranges and have the macro pull data from the selected workbook and put it on the one the macro was run in.
My issue is every month we get files with new names so I am trying to avoid having to change the hard coded names for the workbooks each month.
Again any help is appreciated. Thanks.