Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Make a directory on the fly

I'm trying to write a vb routine that will save a file in
a certain directory. I want to test for the existence of
the directory and create it if it doesn't exist, before
saving the file.

please help?
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Make a directory on the fly

Here is a sub I use to create a directory and save a backup file in that
directory. Modify to suit.

Sub Backup() 'kept in personal.xls & assigned to toolbar button
On Error GoTo BackupFile
MkDir CurDir & "\Backup"
BackupFile:
With ActiveWorkbook
MyWB = .Path & "\BACKUP\" & .Name
.SaveCopyAs MyWB
.Save
End With
End Sub

--
Don Guillett
SalesAid Software

"Jonefer" wrote in message
...
I'm trying to write a vb routine that will save a file in
a certain directory. I want to test for the existence of
the directory and create it if it doesn't exist, before
saving the file.

please help?
Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Make a directory on the fly


Try something like this: - adjusted for your names


On Error Resume Next
MkDir ThisWorkbook.Path & "\NEW DIRECTORY NAME"
ChDir ThisWorkbook.Path & "\NEW DIRECTORY NAME"
ThisWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\NEW DIRECTOR
NAME\MyFileName.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False



HT

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Make a directory on the fly

Just trap the error - less work than testing.

On Error Resume Next
mkdir "C:\MyDirectory"
On Error goto 0

If your directory is several levels, then you might need to work down the
structure

On Error Resume Next
mkdir "c:\Level1"
mkdir "c:\Level1\Level2"
mkdir "c:\Level1\Level2\Level3"
On Error goto 0

If there might be a problem with permissions, then you might need to check
for the existence after the above.

--
Regards,
Tom Ogilvy



Jonefer wrote in message
...
I'm trying to write a vb routine that will save a file in
a certain directory. I want to test for the existence of
the directory and create it if it doesn't exist, before
saving the file.

please help?
Thanks



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
How to automatically make excel detect directory path for linked f rushdhih Excel Discussion (Misc queries) 2 February 20th 09 10:41 AM
Cell reference to make a directory path Dan Deschambault Excel Worksheet Functions 10 July 25th 07 07:25 PM
is there a add-on for excel to make mp3 list from directory Ellard Excel Discussion (Misc queries) 3 December 12th 06 02:44 AM
How do i make a telephone directory for the office Anil New Users to Excel 1 May 20th 06 10:12 PM
How do I make a school directory? Kathy New Users to Excel 2 May 9th 06 04:50 PM


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