Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Activate Workbook

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Activate Workbook

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Activate Workbook

I think this is probably more complicated than I really need to make things.
I make the users open the files I need the sheet to access data from already.
I do this just because I really can't control what directory structure the
files are contained in so rather than make them to a lot of interaction I
just instruct them to open the 4 data files. Then I use an input box to grab
the number contained in the file name. After that I use the following
statement to acftivate the workbook and grab the data I need from it:

Windows(BankNum & "-UserReport.csv").Activate

The problem is I tired to use:

Windows(BankNum & * & "Delete.csv").Activate and I tried
Windows(BankNum & "*delete.csv").Activate


to activate the 4th file that had the date and time between the banknumber
and the word delete but neither of the above statements worked. If there a
simpler way of using this already open worksheet than running all of the code
you suggested?


"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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Activate Workbook

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activate workbook TimT Excel Programming 5 November 29th 05 08:41 PM
Activate Workbook Dolphinv4 Excel Discussion (Misc queries) 2 October 22nd 05 01:45 PM
Workbook.activate Jeff Excel Discussion (Misc queries) 1 December 13th 04 10:22 PM
Activate Other Workbook pauluk[_37_] Excel Programming 16 April 20th 04 07:02 PM
Activate Workbook Fred[_16_] Excel Programming 1 December 2nd 03 05:15 PM


All times are GMT +1. The time now is 12:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"