Open File *approved.xls

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi

How would I write the code to open a file where the only the second part of
the file name is unique.
I have 2 files in 1 folder, called 080609.approved.xls and
080608.restricted.xls. I need to specifically open only the restricted file.

This is very frustrating please help

Thanks
Richard
 
Hi Richard,

Try something like:

'========>>
Option Explicit

Public Sub Tester()
Dim sFile As String
Dim sPath As String
Const sStr As String = "*Restricted.xl*"
Dim sSep As String

sSep = Application.PathSeparator
sPath = Application.DefaultFilePath '<<==== CHANGE

If Right(sPath, 1) <> sSep Then
sPath = sPath & sSep
End If

sFile = Dir(sPath & sStr)
Do While sFile <> vbNullString
Workbooks.Open (sFile)
sFile = Dir()
Loop
End Sub
'<<========
 
test
 

Attachments

  • test.webp
    test.webp
    36.1 KB · Views: 84
Norman

That seems to just set the file name to *restricted.xl* rather than *
representing a wildcard or variable start to the file name

Richard
 
Norman

Found/worked out what I need

For Each objFile_1 In objFolder_1.Files
If InStr(objFile_1, "restricted") Then
strName_1 = objFile_1.Name
End If
Next 'objFile_1

Thanks for the pointer
 
Hi Richard,
That seems to just set the file name to *restricted.xl* rather than *
representing a wildcard or variable start to the file name

For me, the suggested code will open all
files of the designated type.

Thus, for example, the files:

080608.restricted.xls
090608.restricted.xls

would both be opened.
 
True, but after the file has been used it is transferred to another folder,
in order to keep todays, the previous day and all other files seperate.
 

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