Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Open file with unknown extra characters at end of filename


Excel Experts,

I want my code to open a file each morning but there will be extra unknown
characters at the end of the filename.

I believe I need to use a * to represent these, but I can't get the syntax
correct.

The file I want to open is:
C:\MyDocs\MC ID 101805C or
C:\MyDocs\MC ID 101805D

Without adjusting for the extra character, my code is similar to:

Sub OpenFile()

Dim strPath As String
Dim StrPrefix As String
Dim strDate As String

Const strPath As String = "C:\MyDocs\"
Const strPrefix As String = "MC ID "

strDate = Evaluate("=TODAY()")
strDate = Format(strDate, "mmddyy")

Workbooks.Open (strPath & strPrefix & strDate)

End Sub

I tried
Workbooks.Open (strPath & strPrefix & strDate & "*") , or
Workbooks.Open (strPath & strPrefix & strDate*)

but I'm missing something.

How would I modify the code to account for the extra character at the end?

Thanks in advance,
Alan

--
achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Open file with unknown extra characters at end of filename

Hi Alan,

You'll probably want to use the Dir$() function to get the actual filename
before opening. There's no way to open a workbook directly by using
wildcards.

Dim sActualPath As String

sActualPath = Dir$(strPath & strPrefix & strDate & "*")

If Len(sActualPath) Then
'/ OPEN WB

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

achidsey wrote:
Excel Experts,

I want my code to open a file each morning but there will be extra
unknown characters at the end of the filename.

I believe I need to use a * to represent these, but I can't get the
syntax correct.

The file I want to open is:
C:\MyDocs\MC ID 101805C or
C:\MyDocs\MC ID 101805D

Without adjusting for the extra character, my code is similar to:

Sub OpenFile()

Dim strPath As String
Dim StrPrefix As String
Dim strDate As String

Const strPath As String = "C:\MyDocs\"
Const strPrefix As String = "MC ID "

strDate = Evaluate("=TODAY()")
strDate = Format(strDate, "mmddyy")

Workbooks.Open (strPath & strPrefix & strDate)

End Sub

I tried
Workbooks.Open (strPath & strPrefix & strDate & "*")
, or Workbooks.Open (strPath & strPrefix & strDate*)

but I'm missing something.

How would I modify the code to account for the extra character at the
end?

Thanks in advance,
Alan



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
Extra empty workbook opens up when any excel file is open Anindyo Dutta Excel Discussion (Misc queries) 1 February 25th 09 01:19 PM
Macro to open most recent file with a particular filename string kwiklearner Excel Discussion (Misc queries) 1 August 23rd 06 01:24 AM
Unknown Characters Maccas Excel Discussion (Misc queries) 1 July 30th 05 12:09 PM
Macro to read filename in cell and open new file April Excel Programming 2 July 27th 05 02:49 PM
Why doesn't the File Open list sort into filename order? cycler New Users to Excel 7 July 16th 05 06:44 PM


All times are GMT +1. The time now is 04:18 AM.

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"