Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Opening a file with date extension

Hi,
I have a workbook that opens a file, imports data and closes it down again.
The problem I have or will have:
The file that holds the data will change the name by having a date added, so
this will now mean I will have to manualy open the file and minus off the
date so that I can import.
Is there a way the macro can ignore the date so that it would still open the
file and import the data?
Again - your support is greatly appreciated
John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Opening a file with date extension

You could do a Dir before opening to get the full file name

sFilename = Dir("C:\Test\My Import File*.xls"

note that this will return the first found if there are many.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"JohnUK" wrote in message
...
Hi,
I have a workbook that opens a file, imports data and closes it down

again.
The problem I have or will have:
The file that holds the data will change the name by having a date added,

so
this will now mean I will have to manualy open the file and minus off the
date so that I can import.
Is there a way the macro can ignore the date so that it would still open

the
file and import the data?
Again - your support is greatly appreciated
John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Opening a file with date extension

Hi,

Dir doesn't return the full path, so you have to use something like
this:

sPath = "C:\test"
sFilename = "My Import File*.xls"
if len(dir(spath & "\" & sfilename))=0 then
msgbox "No file"
else
sFilename = spath & "\" & dir(spath & "\" & sfilename)
end if

Regards,
Ivan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Opening a file with date extension

Hi Ivan,
Thanks for coming in as well.
I have tried your code, but what extra piece of code do I need to actualy
open the file once found?
John

"Ivan Raiminius" wrote:

Hi,

Dir doesn't return the full path, so you have to use something like
this:

sPath = "C:\test"
sFilename = "My Import File*.xls"
if len(dir(spath & "\" & sfilename))=0 then
msgbox "No file"
else
sFilename = spath & "\" & dir(spath & "\" & sfilename)
end if

Regards,
Ivan


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Opening a file with date extension

Hi John,

sPath = "C:\test"
sFilename = "My Import File*.xls"
if len(dir(spath & "\" & sfilename))=0 then
msgbox "No file"
else
sFilename = spath & "\" & dir(spath & "\" & sfilename)

dim wb as workbook
set wb = workbooks.open sfilename

end if

You can move "dim wb as workbook" into top of the procedure, if you
prefer this location or to the top of the module to be able to work
with wb in other procedures within the module.

Regards,
Ivan



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Opening a file with date extension

Ivan,
This what I have so far:

Dim wb As Workbook
spath = Application.DefaultFilePath
sfilename = "Competitor Pricing Monitor Update.*.xls"
If Len(Dir(spath & "\" & sfilename)) = 0 Then
MsgBox "No file"
Else
sfilename = spath & "\" & Dir(spath & "\" & sfilename)

'set wb = workbooks.open sfilename

End If

The 'set wb = workbooks.open sfilename' has turned red

Not much good at this am I?

What am I missing?

"Ivan Raiminius" wrote:

Hi John,

sPath = "C:\test"
sFilename = "My Import File*.xls"
if len(dir(spath & "\" & sfilename))=0 then
msgbox "No file"
else
sFilename = spath & "\" & dir(spath & "\" & sfilename)

dim wb as workbook
set wb = workbooks.open sfilename

end if

You can move "dim wb as workbook" into top of the procedure, if you
prefer this location or to the top of the module to be able to work
with wb in other procedures within the module.

Regards,
Ivan


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Opening a file with date extension

mmm,
Thanks Bob
I dont even know how to apply it. I tried putting it into the code and
turned red??
How about if I had the file already open, for example:
Windows("Price Update 22-May-06.xls").Activate
But the code would ignore the 22-May-06?
John

"Bob Phillips" wrote:

You could do a Dir before opening to get the full file name

sFilename = Dir("C:\Test\My Import File*.xls"

note that this will return the first found if there are many.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"JohnUK" wrote in message
...
Hi,
I have a workbook that opens a file, imports data and closes it down

again.
The problem I have or will have:
The file that holds the data will change the name by having a date added,

so
this will now mean I will have to manualy open the file and minus off the
date so that I can import.
Is there a way the macro can ignore the date so that it would still open

the
file and import the data?
Again - your support is greatly appreciated
John




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Opening a file with date extension

John,

Assuming that you have that directory active, all you need is something like

sFile = Dir("Price Update*,xls")
If sFile < "" Then
Workbooks.Open(sFile)
End If

If the directory is not active, you need something like

Dim sPath As String
Dim sFile As String

sPath = "C:\MyTest\"
sFile = Dir(sPath & "Price Update*.xls")
If sFile < "" Then
Workbooks.Open (sFile)
End If


If you have it already open, why do you need to open it?

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"JohnUK" wrote in message
...
mmm,
Thanks Bob
I dont even know how to apply it. I tried putting it into the code and
turned red??
How about if I had the file already open, for example:
Windows("Price Update 22-May-06.xls").Activate
But the code would ignore the 22-May-06?
John

"Bob Phillips" wrote:

You could do a Dir before opening to get the full file name

sFilename = Dir("C:\Test\My Import File*.xls"

note that this will return the first found if there are many.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"JohnUK" wrote in message
...
Hi,
I have a workbook that opens a file, imports data and closes it down

again.
The problem I have or will have:
The file that holds the data will change the name by having a date

added,
so
this will now mean I will have to manualy open the file and minus off

the
date so that I can import.
Is there a way the macro can ignore the date so that it would still

open
the
file and import the data?
Again - your support is greatly appreciated
John






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Opening a file with date extension

Many thanks Bob your code worked a treat.
I thought as a last resort I would go for the file already open option. But
then having said that I am having trouble with the already open file being
recognised by the code. - See my reply to Ivan

John
"Bob Phillips" wrote:

John,

Assuming that you have that directory active, all you need is something like

sFile = Dir("Price Update*,xls")
If sFile < "" Then
Workbooks.Open(sFile)
End If

If the directory is not active, you need something like

Dim sPath As String
Dim sFile As String

sPath = "C:\MyTest\"
sFile = Dir(sPath & "Price Update*.xls")
If sFile < "" Then
Workbooks.Open (sFile)
End If


If you have it already open, why do you need to open it?

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"JohnUK" wrote in message
...
mmm,
Thanks Bob
I dont even know how to apply it. I tried putting it into the code and
turned red??
How about if I had the file already open, for example:
Windows("Price Update 22-May-06.xls").Activate
But the code would ignore the 22-May-06?
John

"Bob Phillips" wrote:

You could do a Dir before opening to get the full file name

sFilename = Dir("C:\Test\My Import File*.xls"

note that this will return the first found if there are many.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"JohnUK" wrote in message
...
Hi,
I have a workbook that opens a file, imports data and closes it down
again.
The problem I have or will have:
The file that holds the data will change the name by having a date

added,
so
this will now mean I will have to manualy open the file and minus off

the
date so that I can import.
Is there a way the macro can ignore the date so that it would still

open
the
file and import the data?
Again - your support is greatly appreciated
John






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
Determine Excel file version with no file extension. tjlumpkin Excel Discussion (Misc queries) 2 July 23rd 09 06:59 AM
file format or file extension is not valid...error message Ballun Excel Discussion (Misc queries) 0 May 7th 09 09:06 PM
Additional file with no extension created during File Save As proc Peter Rooney Excel Discussion (Misc queries) 2 August 11th 05 02:48 PM
I need to download an exel spreadsheet file. (file extension :xls) buckrogers Excel Discussion (Misc queries) 2 December 8th 04 11:08 PM
Opening CSV file causes date differences Tom Ogilvy Excel Programming 0 August 6th 03 12:26 AM


All times are GMT +1. The time now is 06:02 AM.

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"