Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Directory with Excel Macro

Status
Not open for further replies.

Dawber

Technical User
Joined
Jun 29, 2001
Messages
86
Location
GB
Is it possible to create a directory from an Excel macro. If so, please could someone let me have the relevant code, I need to create a directory eg. C:\book1 and then save book1.xls within this new folder.
 
Have a look at VBA general help on MkDir:
Creates a new directory or folder.

Syntax

MkDir path

The required path argument is a string expression that identifies the directory or folder to be created. The path may include the drive. If no drive is specified, MkDir creates the new directory or folder on the current drive.

Here's their code example:
Code:
MkDir "MYDIR"	' Make new directory or folder

If uou don't specify Fullpath the Directory is created in Excel's current directory (check what that is by using
Code:
CurDir
)


HTH

Cheers
Nikki

ps - plz post VBA questions in the VBA forum ;-)
 
Making the directory is simple, if you write the name of the directory into the code:

Code:
MkDir "C:\book1"

If you use the macro in lots of files, then use a variable to catch the name of the current file and then hand it onto
Code:
MkDir
, for example:

Code:
Dim VariableName as String
VariableName = ActiveWorkbook.Name
MkDir "C:\" & VariableName

After that you can save the file into the directory.

Carol
Berlin, Germany :-)
 
Hahaha, two people, one thought. Sorry.

Carol
Berlin, Germany :-)
 
that's ok ;-) happens tooooo often 2 me 2

thank gawd we posted the same reply [bigcheeks] otherwise it 'ud have been too confusing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top