ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding a folder with code (https://www.excelbanter.com/excel-programming/355040-adding-folder-code.html)

Tyrell

Adding a folder with code
 
How do I create a folder, if one does not exist, using VBA in Excel when the
workbook is opened and not create a folder if the specified folder already
exists?
--
Tyrell Fickenscher
Plant Manager / Agronomist

Tom Ogilvy

Adding a folder with code
 
On Error Resume Next
mkdir "C:\MyFolder"
On Error goto 0

this assumes the existence of only the last folder in the chain is in
question.

--
Regards,
Tom Ogilvy


"Tyrell" wrote in message
...
How do I create a folder, if one does not exist, using VBA in Excel when

the
workbook is opened and not create a folder if the specified folder already
exists?
--
Tyrell Fickenscher
Plant Manager / Agronomist




Jim Thomlinson[_5_]

Adding a folder with code
 
Give this a whirl...

Sub test()
On Error GoTo MakeDirectory
ChDir ("C:\Test2")
On Error GoTo 0

Exit Sub
MakeDirectory:
MkDir "C:\Test2"
Resume Next

End Sub
--
HTH...

Jim Thomlinson


"Tyrell" wrote:

How do I create a folder, if one does not exist, using VBA in Excel when the
workbook is opened and not create a folder if the specified folder already
exists?
--
Tyrell Fickenscher
Plant Manager / Agronomist


Dave Peterson

Adding a folder with code
 
I just try to create it and ignore any error message.

on error resume next
mkdir "C:\myfolder"
on error goto 0



Tyrell wrote:

How do I create a folder, if one does not exist, using VBA in Excel when the
workbook is opened and not create a folder if the specified folder already
exists?
--
Tyrell Fickenscher
Plant Manager / Agronomist


--

Dave Peterson


All times are GMT +1. The time now is 12:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com