Opening a xl workbook using wildcard

D

damorrison

Hi,
I am using an input box to to select a folder for where the .xls
workbook is
##########
Sub Macro3()
Dim i As String
i = InputBox("Enter Job Number", , "Job Number")
Workbooks.Open Filename:="C:\" & i & "\Kicking Quotes.xls"
End Sub

#########
Each folder has 1 workbook but the workbook does not always have the
same name.

How can I open whatever workbook is in the folder selected?

Thanks
 
J

Jim Rech

This opens the first XLS file that the Dir function returns:

Sub a()
Dim DName As String
Dim FName As String
DName = InputBox("Enter Job Number", , "Job Number")
If DName <> "" Then
FName = Dir("C:\" & DName & "\*.xls")
If FName <> "" Then
Workbooks.Open "C:\" & DName & "\" & FName
End If
End If
End Sub


--
Jim
| Hi,
| I am using an input box to to select a folder for where the .xls
| workbook is
| ##########
| Sub Macro3()
| Dim i As String
| i = InputBox("Enter Job Number", , "Job Number")
| Workbooks.Open Filename:="C:\" & i & "\Kicking Quotes.xls"
| End Sub
|
| #########
| Each folder has 1 workbook but the workbook does not always have the
| same name.
|
| How can I open whatever workbook is in the folder selected?
|
| Thanks
 
D

damorrison

This opens the first XLS file that the Dir function returns:

Sub a()
    Dim DName As String
    Dim FName As String
    DName = InputBox("Enter Job Number", , "Job Number")
    If DName <> "" Then
        FName = Dir("C:\" & DName & "\*.xls")
        If FName <> "" Then
            Workbooks.Open "C:\" & DName & "\" & FName
        End If
    End If
End Sub
Thank You very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top