Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default select new wkbk when name varies

I hope I can describe my situation well enough that I can get a
suggestion from the experts on the group. Here goes.....

During the execution of a macro a new workbook will be opened, this
new workbook will be created by a web based application that has the
option to download data to an excel workbook. I would like to have the
macro access this new workbook to extract some data. The problem is,
the name of the workbook that is generated by the web based
application varies, here are some examples of the names:

GEALLgz0ebr55kdkez3ukfgcf5e452641732.xls
GEALLgz0ebr55kdkez3ukfgcf5e452915659.xls
GEALLgz0ebr55kdkez3ukfgcf5e4521132788.xls

It appears the start of the name is always the same but the end
varies, maybe some time stamp.

How do I select this workbook based on for instance, the first 10
characters of the name?

Does this make sense?


John Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default select new wkbk when name varies

I think you would want the latest file with the a specified first 10
characters.

Sub OpenLatest()

Folder = "C:\Temp\"
BaseName = "GEALLgz0eb"

Set FSO = CreateObject _
("Scripting.FileSystemObject")

LatestDate = 0
FName = Dir(Folder & BaseName & "*.xls")
LatestFName = ""
Do While FName < ""
Set FSN = FSO.getfile(Folder & FName)
If FSN.DateLastModified LatestDate Then
LatestFName = FSN.Path
End If
a = 1
FName = Dir()
Loop

If LatestDate = 0 Then
MsgBox ("Cannot find file - Exiting sub")
Exit Sub
End If

Set bk = Workbooks.Open(Filename:=LatestFName)

End Sub


"John Keith" wrote:

I hope I can describe my situation well enough that I can get a
suggestion from the experts on the group. Here goes.....

During the execution of a macro a new workbook will be opened, this
new workbook will be created by a web based application that has the
option to download data to an excel workbook. I would like to have the
macro access this new workbook to extract some data. The problem is,
the name of the workbook that is generated by the web based
application varies, here are some examples of the names:

GEALLgz0ebr55kdkez3ukfgcf5e452641732.xls
GEALLgz0ebr55kdkez3ukfgcf5e452915659.xls
GEALLgz0ebr55kdkez3ukfgcf5e4521132788.xls

It appears the start of the name is always the same but the end
varies, maybe some time stamp.

How do I select this workbook based on for instance, the first 10
characters of the name?

Does this make sense?


John Keith


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default select new wkbk when name varies

dim wb as workbook
for each wb in Workbooks
if left(wb.name,10) = "GEALLgz0ebr" then
exit for
end if
next
if not wb is nothing then
msgbox wb.name,,"workbook selected"
end if



orif wb.name LIKE "GEALLgz0ebr*" then



"John Keith" wrote:

I hope I can describe my situation well enough that I can get a
suggestion from the experts on the group. Here goes.....

During the execution of a macro a new workbook will be opened, this
new workbook will be created by a web based application that has the
option to download data to an excel workbook. I would like to have the
macro access this new workbook to extract some data. The problem is,
the name of the workbook that is generated by the web based
application varies, here are some examples of the names:

GEALLgz0ebr55kdkez3ukfgcf5e452641732.xls
GEALLgz0ebr55kdkez3ukfgcf5e452915659.xls
GEALLgz0ebr55kdkez3ukfgcf5e4521132788.xls

It appears the start of the name is always the same but the end
varies, maybe some time stamp.

How do I select this workbook based on for instance, the first 10
characters of the name?

Does this make sense?


John Keith


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default select new wkbk when name varies

On Mon, 12 Oct 2009 08:20:02 -0700, Patrick Molloy
wrote:

dim wb as workbook
for each wb in Workbooks
if left(wb.name,10) = "GEALLgz0ebr" then
exit for
end if
next
if not wb is nothing then
msgbox wb.name,,"workbook selected"
end if


Thanks Patrick, I'll play later tonight.


John Keith

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default select new wkbk when name varies

On Mon, 12 Oct 2009 08:18:01 -0700, Joel
wrote:

I think you would want the latest file with the a specified first 10
characters.


Thanks Joel,

I'll play with this tonight.


John Keith

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
Copy sheets from source wkbk to another wkbk Diddy Excel Programming 0 August 21st 08 01:48 PM
Find WkBk Path, Then use this path to open another WkBk in Subfold dim Excel Programming 10 April 23rd 08 01:00 AM
Sum of a range that varies Sebastien Excel Discussion (Misc queries) 1 February 19th 08 04:19 PM
Creating a Hyperlink from 1 WKBK to open another WKBK and activate Barb Reinhardt Excel Programming 10 May 31st 07 06:45 PM
run a procedure in 1 wkbk from another wkbk carenla Excel Programming 1 July 7th 05 05:40 PM


All times are GMT +1. The time now is 04:50 PM.

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

About Us

"It's about Microsoft Excel"