Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default How to create multiple subfolders using VBA

Hello and thanks for reading my question.

I need some VBA programming help.

I have a main folder with subfolders in it. I want to add a new subfolder
to each subfolder in the directory.

It would look something like this

Main Folder
Subfolder1
NewSubfolder
Subfolder2
NewSubfolder
Subfolder3
NewSubfolder
Subfolder4
NewSubfolder

I was able to use this VBA to do it for one folder, but I need it to look
through all Subfolders

MkDir ("C:\MainFolder\Subfolder1\Subfolder1.1")

How do I look through each subfolder and add a new subfolder under each
subfolder?

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to create multiple subfolders using VBA

Just make the subfolders in order:

on error resume next 'in case the folder already exists
mkdir "C:\mainfolder"
mkdir "C:\mainfolder\subfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder2"
mkdir "C:\mainfolder\subfolder2"
mkdir "C:\mainfolder\subfolder2\newsubfolder1"
mkdir "C:\mainfolder\subfolder2\newsubfolder2"
....
on error goto 0



ScottMsp wrote:

Hello and thanks for reading my question.

I need some VBA programming help.

I have a main folder with subfolders in it. I want to add a new subfolder
to each subfolder in the directory.

It would look something like this

Main Folder
Subfolder1
NewSubfolder
Subfolder2
NewSubfolder
Subfolder3
NewSubfolder
Subfolder4
NewSubfolder

I was able to use this VBA to do it for one folder, but I need it to look
through all Subfolders

MkDir ("C:\MainFolder\Subfolder1\Subfolder1.1")

How do I look through each subfolder and add a new subfolder under each
subfolder?

Thanks in advance.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default How to create multiple subfolders using VBA

Dave,

My problem is that I have over 1,000 folders that I need to make. I presume
there is a more effecient way than creating over 1,000 lines of code?

Thanks in advance.

"Dave Peterson" wrote:

Just make the subfolders in order:

on error resume next 'in case the folder already exists
mkdir "C:\mainfolder"
mkdir "C:\mainfolder\subfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder2"
mkdir "C:\mainfolder\subfolder2"
mkdir "C:\mainfolder\subfolder2\newsubfolder1"
mkdir "C:\mainfolder\subfolder2\newsubfolder2"
....
on error goto 0



ScottMsp wrote:

Hello and thanks for reading my question.

I need some VBA programming help.

I have a main folder with subfolders in it. I want to add a new subfolder
to each subfolder in the directory.

It would look something like this

Main Folder
Subfolder1
NewSubfolder
Subfolder2
NewSubfolder
Subfolder3
NewSubfolder
Subfolder4
NewSubfolder

I was able to use this VBA to do it for one folder, but I need it to look
through all Subfolders

MkDir ("C:\MainFolder\Subfolder1\Subfolder1.1")

How do I look through each subfolder and add a new subfolder under each
subfolder?

Thanks in advance.


--

Dave Peterson
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to create multiple subfolders using VBA

I have not tried this with VBA, but I have done it with AutoCAD. You could
use Excel to write the code. The main trick is to use concatenation to
build up the single lines of code, and then copy the column with the
concatenated cells to your macro.

Brad

Excel 2002 on XP Pro SP 3
Excel 2007 on Vista 64
"ScottMsp" wrote in message
...
Dave,

My problem is that I have over 1,000 folders that I need to make. I
presume
there is a more effecient way than creating over 1,000 lines of code?

Thanks in advance.

"Dave Peterson" wrote:

Just make the subfolders in order:

on error resume next 'in case the folder already exists
mkdir "C:\mainfolder"
mkdir "C:\mainfolder\subfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder2"
mkdir "C:\mainfolder\subfolder2"
mkdir "C:\mainfolder\subfolder2\newsubfolder1"
mkdir "C:\mainfolder\subfolder2\newsubfolder2"
....
on error goto 0



ScottMsp wrote:

Hello and thanks for reading my question.

I need some VBA programming help.

I have a main folder with subfolders in it. I want to add a new
subfolder
to each subfolder in the directory.

It would look something like this

Main Folder
Subfolder1
NewSubfolder
Subfolder2
NewSubfolder
Subfolder3
NewSubfolder
Subfolder4
NewSubfolder

I was able to use this VBA to do it for one folder, but I need it to
look
through all Subfolders

MkDir ("C:\MainFolder\Subfolder1\Subfolder1.1")

How do I look through each subfolder and add a new subfolder under each
subfolder?

Thanks in advance.


--

Dave Peterson
.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default How to create multiple subfolders using VBA

You could use the scripting file system object. You didn't elaborate on any
naming convention. The example below takes each subfolder of "C:\Test" and
creates a new second level subfolder named "newSub" in it if such a
subfolder doesn't already exist.

Steve

'----------------------------------------
Sub MakeManySubs()
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Test")
For Each subF In f.Subfolders
If Not fso.FolderExists(subF & "\newSub") Then
fso.CreateFolder (subF & "\newSub")
End If
Next subF
Set fso = Nothing
End Sub


'---------------------------------------



"ScottMsp" wrote in message
...
Dave,

My problem is that I have over 1,000 folders that I need to make. I
presume
there is a more effecient way than creating over 1,000 lines of code?

Thanks in advance.

"Dave Peterson" wrote:

Just make the subfolders in order:

on error resume next 'in case the folder already exists
mkdir "C:\mainfolder"
mkdir "C:\mainfolder\subfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder2"
mkdir "C:\mainfolder\subfolder2"
mkdir "C:\mainfolder\subfolder2\newsubfolder1"
mkdir "C:\mainfolder\subfolder2\newsubfolder2"
....
on error goto 0



ScottMsp wrote:

Hello and thanks for reading my question.

I need some VBA programming help.

I have a main folder with subfolders in it. I want to add a new
subfolder
to each subfolder in the directory.

It would look something like this

Main Folder
Subfolder1
NewSubfolder
Subfolder2
NewSubfolder
Subfolder3
NewSubfolder
Subfolder4
NewSubfolder

I was able to use this VBA to do it for one folder, but I need it to
look
through all Subfolders

MkDir ("C:\MainFolder\Subfolder1\Subfolder1.1")

How do I look through each subfolder and add a new subfolder under each
subfolder?

Thanks in advance.


--

Dave Peterson
.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to create multiple subfolders using VBA

You could set up a loop, but you didn't share enough info to do that.

You could put the folder names in a worksheet (A1:A1000) and loop through that.

Brad wrote:

I have not tried this with VBA, but I have done it with AutoCAD. You could
use Excel to write the code. The main trick is to use concatenation to
build up the single lines of code, and then copy the column with the
concatenated cells to your macro.

Brad

Excel 2002 on XP Pro SP 3
Excel 2007 on Vista 64
"ScottMsp" wrote in message
...
Dave,

My problem is that I have over 1,000 folders that I need to make. I
presume
there is a more effecient way than creating over 1,000 lines of code?

Thanks in advance.

"Dave Peterson" wrote:

Just make the subfolders in order:

on error resume next 'in case the folder already exists
mkdir "C:\mainfolder"
mkdir "C:\mainfolder\subfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder1"
mkdir "C:\mainfolder\subfolder1\newsubfolder2"
mkdir "C:\mainfolder\subfolder2"
mkdir "C:\mainfolder\subfolder2\newsubfolder1"
mkdir "C:\mainfolder\subfolder2\newsubfolder2"
....
on error goto 0



ScottMsp wrote:

Hello and thanks for reading my question.

I need some VBA programming help.

I have a main folder with subfolders in it. I want to add a new
subfolder
to each subfolder in the directory.

It would look something like this

Main Folder
Subfolder1
NewSubfolder
Subfolder2
NewSubfolder
Subfolder3
NewSubfolder
Subfolder4
NewSubfolder

I was able to use this VBA to do it for one folder, but I need it to
look
through all Subfolders

MkDir ("C:\MainFolder\Subfolder1\Subfolder1.1")

How do I look through each subfolder and add a new subfolder under each
subfolder?

Thanks in advance.

--

Dave Peterson
.


--

Dave Peterson
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
Add subfolders and name - Possible? Trish Smith Excel Programming 2 August 17th 08 02:29 AM
Code to create folder and subfolders JP[_3_] Excel Programming 4 November 2nd 07 07:16 PM
repeating code on files in multiple subfolders ED007 Excel Programming 1 March 14th 07 09:53 PM
copy subfolders, replace text in files and save files in copied subfolders pieros Excel Programming 0 November 1st 05 12:08 PM
Create subfolders in a folder Myrna Rodriguez Excel Programming 2 July 15th 04 04:10 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"