How can I use wild cards when calling .xls files to open ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone tell me if you can use wild cards while calling an excel file to be opend and if so how.
for exampl

This is a line of vba code I used and it doesn't wor
Set ExcelSheet = GetObject("C:\MyExcelFiles\"MyExcelFile*.xls")

Is there a way to use wild cards like the astrik "*" when using vba code to get and open an .xls file ??

Thankyou, Da
 
Dim sPath as String, sFile as String, sName as String
sPath = "C:\MyExcelFiles\"
sFile = "MyExcelFile*.xls"
sName = Dir(sPath & sFile)
if sName <> "" then
set ExcelSheet = GetObject(sPath & sName)
Else
msgbox "No Match"
End If

--
Regards,
Tom Ogilvy



Dan T said:
Can someone tell me if you can use wild cards while calling an excel file to be opend and if so how.
for example

This is a line of vba code I used and it doesn't work
Set ExcelSheet = GetObject("C:\MyExcelFiles\"MyExcelFile*.xls")

Is there a way to use wild cards like the astrik "*" when using vba code
to get and open an .xls file ???
 
You could also try

Dim fName As String

ChDrive "C"
ChDir "C:\MyExcelFiles"
fName = Application.GetOpenFilename("Excel files,*.xls", _
, "Select file to open")
If fName <> "False" Then
Set ExcelSheet = GetObject(fName)
End If


Kevin Beckham
-----Original Message-----
Can someone tell me if you can use wild cards while
calling an excel file to be opend and if so how.
for example

This is a line of vba code I used and it doesn't work
Set ExcelSheet = GetObject ("C:\MyExcelFiles\"MyExcelFile*.xls")

Is there a way to use wild cards like the astrik "*" when
using vba code to get and open an .xls file ???
 

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

Back
Top