Reference a workbook from a list

elg0007

New Member
Joined
Jun 22, 2015
Messages
10
I want a macro that will allow users to choose a workbook from a specified folder, and copy information from that workbook. So I guess I would like excel to provide a list of workbooks in a folder (if Possible), then have the user select the one they want, then have excel use that workbook for the rest of the code. I'm guessing it involves something with application. but I'm not sure. Can anyone help me out? Thanks!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,

It sounds like you need a macro like this:
Code:
Sub GetFile()

    Dim WB As Workbook
    Dim FileChosen As Integer
    Dim fd As FileDialog
    
    ' Get a file name
    Set fd = Application.FileDialog(msoFileDialogOpen)
    FileChosen = fd.Show
    If FileChosen <> -1 Then
        MsgBox "Cancelled"
        Exit Sub
    End If
    
    ' Open workbook
    Set WB = Workbooks.Open(fd.SelectedItems(1))

End Sub

You can then use the WB object as a handle to the workbook.
 
Upvote 0
That works great, thank you! Do you know of a way to have it default to looking at a certain page in the network, instead of defaulting to My Documents or Desktop or something? Maybe have it view a shared documents website?
 
Upvote 0
Hi,

This is how you start it in a folder called C:\Archive. It may work with network shares as well.

Rich (BB code):
Sub GetFile()

    Dim WB As Workbook
    Dim FileChosen As Integer
    Dim fd As FileDialog
    
    ' Get a file name
    Set fd = Application.FileDialog(msoFileDialogOpen)
    fd.InitialFileName = "C:\Archive"
    FileChosen = fd.Show
    If FileChosen <> -1 Then
        MsgBox "Cancelled"
        Exit Sub
    End If
    
    ' Open workbook
    Set WB = Workbooks.Open(fd.SelectedItems(1))

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,654
Members
449,245
Latest member
PatrickL

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