Opening a file with VBA

Snap Happy

New Member
Joined
Dec 8, 2009
Messages
18
I am trying to open a file from within a macro where part of the file path is unknown ie.e D:Group Files\2011\20110824[unknown variable characters]\epst48.epd.

Does anyone know if there is such a thing as a wild card that can be used to indicate the variable characters that Excel will still recognise?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi, :)

just take the API function "SearchTreeForFile". The function searches for a file - including all subfolders. Path and file name change. You write the path until the last known.

Code:
Option Explicit
Private Declare Function SearchTreeForFile Lib "imagehlp.dll" ( _
    ByVal RootPath As String, ByVal InputPathName As String, _
    ByVal OutputPathBuffer As String) As Long
Public Sub Main()
    Dim strFileName As String
    Dim strPath As String
    Dim strTMP As String
    strFileName = "2.xls" ' adapt
    strPath = "C:\Temp\" ' adapt
    strTMP = FindFile(strPath, strFileName)
    If strTMP <> "" Then
        MsgBox strTMP
    Else
        MsgBox "No!"
    End If
End Sub
Function FindFile(ByVal Path As String, ByVal File As String) As String
    Dim strFile As String * 1024
    If SearchTreeForFile(Path, File, strFile) Then
        FindFile = Left$(strFile, InStr(strFile, vbNullChar) - 1)
    Else
        FindFile = ""
    End If
End Function
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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