PDA

View Full Version : Solved: Partial file name



lijon
08-21-2009, 12:24 PM
Hey, thanks for reading. I'm trying to write code to switch to another open file.

Typically use something like Windows("Book1.xls").activate
But what if we only had the 1st parts of a filename?

Windows("Ticket" & "*" & ".xls").Activate ...Is what i've tried, but it breaks down and won't switch to the other open book.

Any ideas folks?

Thanks thanks. L

GTO
08-21-2009, 12:55 PM
Greetings,

Just to mention - I typically would not use the window caption nor activate. Of course I cannot see your code, but in general, setting a reference to object (workbook/range/etc) will make the code 'happier'....

To your question though, let's try the Like operator:

Option Explicit

Sub exa()
Dim winAPP As Window

For Each winAPP In Application.Windows
If winAPP.Caption Like "Ticket*.xls" Then
winAPP.Activate
Exit For
End If
Next
End Sub

Does that help?

Mark

lijon
08-21-2009, 01:07 PM
Thanks Man! Appreciate the tip. LIKE it is.