Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 709
Default Opening WorkBooks Using VBA Starting With the 1st 2 Characters

OS: MS XP, Excel 2003

I want to open an Excel file using VBA.
I want to use only the 1st 2 Characters of the file name.
The 1st two characters are the week number in a year.
Such as 01, 02, 03, 04 ~~~~, 09, 10, 11 Etc.
How would I use the Wild Card * in the file name to achieve this?
Or is there another way?


Thanks in advanced.


--
Richard
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 421
Default Opening WorkBooks Using VBA Starting With the 1st 2 Characters

Hi Richard,

Assuming that the two (or more)
characters uniquely identify the file
of interest, try something like:

'=========
Public Sub TestIt()
Dim res As String
Dim sStr As String

sStr = "02" '<<==== CHANGE
Call OpenIt(sStr)
End Sub

'------------
Public Sub OpenIt(sPartName As String)
Dim sFile As String
Const sPath As String = _
"C:\Users\Norman\Documents\" '<<==== CHANGE

sFile = Dir(sPath & sPartName & "*.x*")

If Len(sFile) 0 Then
On Error Resume Next
Workbooks.Open Filename:=sPath & sFile
On Error GoTo 0
End If

End Sub
'<<=========

Depending on your requirements, the
two letter string could be passes as
the response to an InputBox or a cell
value.


---
Regards.
Norman


"Richard" wrote in message
...
OS: MS XP, Excel 2003

I want to open an Excel file using VBA.
I want to use only the 1st 2 Characters of the file name.
The 1st two characters are the week number in a year.
Such as 01, 02, 03, 04 ~~~~, 09, 10, 11 Etc.
How would I use the Wild Card * in the file name to achieve this?
Or is there another way?


Thanks in advanced.


--
Richard


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
Opening Excel workbooks Brian G Excel Worksheet Functions 2 December 7th 07 01:49 AM
combine several workbooks without opening Trang Excel Discussion (Misc queries) 4 December 3rd 07 10:55 PM
Opening workbooks calimari Excel Discussion (Misc queries) 2 January 24th 06 01:34 AM
read characters starting from the right until a space is reached wolfpack95 Excel Discussion (Misc queries) 5 January 4th 06 08:46 PM
Opening Workbooks Mininmized DME New Users to Excel 1 December 1st 04 07:53 PM


All times are GMT +1. The time now is 07:08 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"