View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Creating a folder on SaveAs

One way is to ignore any error when you create the folder:

on error resume next
mkdir "D:\store returns"
mkdir "D:\Store Returns\Contacts"
mkdir "D:\Store Returns\Contacts\StoreNo"
on error goto 0

Here's something that Jim Rech Posted:

Option Explicit
Declare Function MakePath Lib "imagehlp.dll" Alias _
"MakeSureDirectoryPathExists" (ByVal lpPath As String) As Long

Sub Test()
MakeDir "c:\aaa\bbb"
End Sub

Sub MakeDir(DirPath As String)
If Right(DirPath, 1) < "\" Then DirPath = DirPath & "\"
MakePath DirPath
End Sub

leerem wrote:

Hi All, Your assistance is required.

How would I progmatically save an excel file to a folder that doesn't yet
exist. I'm writing an attachment to a code that saves a straightforward file,
however when the user saves a new file (eg. a new store has opened) I need
to identify that store by their Store No. with the related files stored
within.

So I need to save the file as for example:

ActiveWorkbook.SaveAs Filename:="D:\Store Returns\Contacts\StoreNo\" &
FileNameSave, FileFormat:=xlNormal

With StoreNo being the New Folder that needs to be created and FileNameSave
as the File Name.

In short how do you create a folder with code.

Any assistance would be much appreciated.

Regards
Lee


--

Dave Peterson