Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Save file using part of folder name


Hi,

Is there a way to save to a folder when only part of the folder name is
known?

The path i want to save it into
H:\2006\2006_SomeProjectName\transmittal.xls

2006 is stored in a variable ProjectYear and will always be know.
SomeProjectName will always be unknown.

So with the exceptioin of SomeProjectName (which i have shown as
question marks) the save path would look something like this.
ProjectPathXLS = "H:\" + ProjectYear + "\" + ProjectYear + ???? + "\
transmittal.xls"

Thanks for any help!


--
Object
------------------------------------------------------------------------
Object's Profile: http://www.excelforum.com/member.php...o&userid=33752
View this thread: http://www.excelforum.com/showthread...hreadid=537649

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Save file using part of folder name

Well, you could perhaps try to discover what it is:

s = "H:\" & ProjectYear & "\"

MyPath = s & ProjectYear & "*" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName < "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName < "." And MyName < ".." Then
' Use bitwise comparison to make sure MyName is a directory.

If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Msgbox s & MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

But to actually save, you would need the actual path which you should be
able to get from the above code.

--
Regards,
Tom Ogilvy



"Object" wrote in
message ...

Hi,

Is there a way to save to a folder when only part of the folder name is
known?

The path i want to save it into
H:\2006\2006_SomeProjectName\transmittal.xls

2006 is stored in a variable ProjectYear and will always be know.
SomeProjectName will always be unknown.

So with the exceptioin of SomeProjectName (which i have shown as
question marks) the save path would look something like this.
ProjectPathXLS = "H:\" + ProjectYear + "\" + ProjectYear + ???? + "\
transmittal.xls"

Thanks for any help!


--
Object
------------------------------------------------------------------------
Object's Profile:

http://www.excelforum.com/member.php...o&userid=33752
View this thread: http://www.excelforum.com/showthread...hreadid=537649



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Save file using part of folder name

Is there only ever one subdirectory under "H:\2006\" ?

What if there were two: (eg) 2006_SomeProjectName and 2006_SomeOtherProject ?
Could that ever happen ?

Tim


"Object" wrote in message
...

Hi,

Is there a way to save to a folder when only part of the folder name is
known?

The path i want to save it into
H:\2006\2006_SomeProjectName\transmittal.xls

2006 is stored in a variable ProjectYear and will always be know.
SomeProjectName will always be unknown.

So with the exceptioin of SomeProjectName (which i have shown as
question marks) the save path would look something like this.
ProjectPathXLS = "H:\" + ProjectYear + "\" + ProjectYear + ???? + "\
transmittal.xls"

Thanks for any help!


--
Object
------------------------------------------------------------------------
Object's Profile: http://www.excelforum.com/member.php...o&userid=33752
View this thread: http://www.excelforum.com/showthread...hreadid=537649



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Save file using part of folder name


Thanks Tom,

However the script keeps stopping at

If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then

any ideas?



Tom Ogilvy Wrote:
Well, you could perhaps try to discover what it is:

s = "H:\" & ProjectYear & "\"

MyPath = s & ProjectYear & "*" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName < "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName < "." And MyName < ".." Then
' Use bitwise comparison to make sure MyName is a directory.

If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Msgbox s & MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

But to actually save, you would need the actual path which you should
be
able to get from the above code.

--
Regards,
Tom Ogilvy




--
Object
------------------------------------------------------------------------
Object's Profile: http://www.excelforum.com/member.php...o&userid=33752
View this thread: http://www.excelforum.com/showthread...hreadid=537649

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Save file using part of folder name


Yes, there are several subdirectories under "H:\2006\". The directory
could potentially not exist aswell, in which case i would like the
script to stop.

Tim Williams Wrote:
Is there only ever one subdirectory under "H:\2006\" ?

What if there were two: (eg) 2006_SomeProjectName and
2006_SomeOtherProject ?
Could that ever happen ?

Tim




--
Object
------------------------------------------------------------------------
Object's Profile: http://www.excelforum.com/member.php...o&userid=33752
View this thread: http://www.excelforum.com/showthread...hreadid=537649



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Save file using part of folder name

Yes, I didn't completely revise the code (it is some of the sample code from
the DIR command)

the offending line should actually be


If (GetAttr(s & MyName) And vbDirectory) = vbDirectory Then

--
Regards,
Tom Ogilvy


"Object" wrote in
message ...

Thanks Tom,

However the script keeps stopping at

If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then

any ideas?



Tom Ogilvy Wrote:
Well, you could perhaps try to discover what it is:

s = "H:\" & ProjectYear & "\"

MyPath = s & ProjectYear & "*" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName < "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName < "." And MyName < ".." Then
' Use bitwise comparison to make sure MyName is a directory.

If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Msgbox s & MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

But to actually save, you would need the actual path which you should
be
able to get from the above code.

--
Regards,
Tom Ogilvy




--
Object
------------------------------------------------------------------------
Object's Profile:

http://www.excelforum.com/member.php...o&userid=33752
View this thread: http://www.excelforum.com/showthread...hreadid=537649



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Save file using part of folder name


Thanks alot Tom, all working perfectly.

Tom Ogilvy Wrote:
Yes, I didn't completely revise the code (it is some of the sample code
from
the DIR command)

the offending line should actually be


If (GetAttr(s & MyName) And vbDirectory) = vbDirectory Then

--
Regards,
Tom Ogilvy





--
Object


------------------------------------------------------------------------
Object's Profile: http://www.excelforum.com/member.php...o&userid=33752
View this thread: http://www.excelforum.com/showthread...hreadid=537649

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
Save file to same directory folder RobN[_2_] Excel Discussion (Misc queries) 2 April 4th 10 08:06 AM
in which folder can you save a .CSV file? chivagirl Excel Discussion (Misc queries) 17 December 31st 07 10:44 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
open file from folder save in new folder tim64[_3_] Excel Programming 20 June 17th 05 07:58 PM
How do I save a read only file or folder? Dick Excel Discussion (Misc queries) 3 March 4th 05 03:29 AM


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