View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Activate Workbook

You changed the code:

If LCase(myFile) Like "xxx_*_delete.xls" Then
to
If LCase(myFile) Like "delete.csv" Then

Was there a reason?

When you changed the code, you're really only looking for delete.csv. It has to
match exactly. Is that what you wanted.

hshayh0rn wrote:

Dave,

When I run this modified code:

Option Explicit
Sub testme01()

Dim myFile As String
Dim myPath As String
Dim FoundIt As Boolean
Dim wkbk As Workbook

'change to point at the folder to check
myPath = "D:\my documents\excel"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = ""
On Error Resume Next
myFile = Dir(myPath & "*.csv")
On Error GoTo 0
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

FoundIt = False
Do While myFile < ""
If LCase(myFile) Like "delete.csv" Then
FoundIt = True
Exit Do
End If
myFile = Dir()
Loop

If FoundIt = True Then
Set wkbk = Workbooks.Open(Filename:=myPath & myFile)
End If

End Sub

Nothing happens. I don't get an error and the file *delete.csv doesn't open.
Is there something missing from the code?

"Dave Peterson" wrote:

Maybe you could just look for that pattern:

Option Explicit
Sub testme01()

Dim myFile As String
Dim myPath As String
Dim FoundIt As Boolean
Dim wkbk As Workbook

'change to point at the folder to check
myPath = "c:\my documents\excel"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = ""
On Error Resume Next
myFile = Dir(myPath & "*.xls")
On Error GoTo 0
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

FoundIt = False
Do While myFile < ""
If LCase(myFile) Like "xxx_*_delete.xls" Then
FoundIt = True
Exit Do
End If
myFile = Dir()
Loop

If FoundIt = True Then
Set wkbk = Workbooks.Open(Filename:=myPath & myFile)
End If

End Sub

You can make that pattern more complex if need be.



hshayh0rn wrote:

I have a macro that I use to activate a couple of different workbooks. My
problem is that one of the workbooks I need to use has a dynamic name. The
name of the workbook is created by a seperate program thats I do not control
and the name is comprised of "XXX_Date of creation_Time of
Creation_Delete.xls". Is there a way to open the book using some type of
wildcard? The XXX and Delete part of the file name are constant.


--

Dave Peterson


--

Dave Peterson