VBA Open Filename not working.

Flailer

New Member
Joined
Jun 28, 2011
Messages
3
I'm trying to use the open filename command to open a specific file for printing the problem is the filename is always changing, I've tried using wildcards but no success. The "00-00.xls" portion of the name changes randomly since the last two digits of the name are seconds, causing the open command to fail sometimes.
Any suggestions?

Thanks

The code:
Workbooks.Open Filename:="c:\DeltaV Reporter\Reports\Daily\daily." & Format(Date, "yyyy-mm-dd") & " " & Hour(Now()) & "-00-00.xls"
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try something like this (not tested)...

Code:
Dim strPath As String, strFileWild As String, strFileOpen As String

strPath = "C:\DeltaV Reporter\Reports\Daily\"
strFileWild = "daily." & Format(Now, "yyyy-mm-dd h-") & "*.xls"
strFileOpen = Dir(strPath & strFile)  'Test if file exists

If strFileOpen <> vbNullString Then
    Workbooks.Open Filename:=strPath & strFileOpen
Else
    MsgBox "Coludn't locate file:" & vbLf & strPath & strFileWild, vbExclamation, "File Not Found"
End If
 
Upvote 0
Thanks for the reply AlphaFrog. I'm still having an issue with the wildcard, the Msg Box shows that its trying to call up the file with the wild card in it.

daily.20110629-11-*.xls

any further thoughts?
 
Upvote 0
Change this...
strFileOpen = Dir(strPath & strFile) 'Test if file exists

To this...
strFileOpen = Dir(strPath & strFileWild) 'Test if file exists
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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