PC Review


Reply
Thread Tools Rate Thread

Add subfolders and name - Possible?

 
 
Trish Smith
Guest
Posts: n/a
 
      17th Aug 2008
Hi,

I was wondering if it would be possible to add subfolders to a folder using
vba?

If it is possible I would like to be able to add subfolders from a list of
names in an Excel sheet.

If anyone could help that would be great :-)

Thank you
--
Trish
 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      17th Aug 2008
Hi Trish,

The following code example should help. Take particular note of the comments.

To make a folder based on a value in a cell then simply make the variable
equal to the cell and ensure that you get the path info correct.

Sub PathsAndThings()

Dim strCurDir As String
Dim strApplicationPath As String
Dim strThisWorkBookPath As String
Dim strMyNewFolder As String

'Current directory is the path where a workbook will be
'saved by default if you click save.
'When Excel is first opened it is the default path
'as set in options but if you use Save As and select another
'path to save the workbook, then that path becomes the
'Current Directory. The same if you select another path
'to open a workbook.
strCurDir = CurDir

MsgBox "The current directory (or path) is " & strCurDir


'Application path is the path of the Excel application
strApplicationPath = Application.Path

MsgBox "The path for the current application is " & strApplicationPath

'This workbook path is the path of the current open workbook
strThisWorkBookPath = Application.ThisWorkbook.Path

MsgBox "The application current project path is " & strThisWorkBookPath

'To create a directory (or folder) use MkDir function
'if you use the function on its own as follows then
'it creates a sub-folder of the Current directory

MkDir "Test folder"

'To make a folder at another location then precede the folder
'with the required path.

MkDir "C:\Users\Username\Test folder"

'Variables can be used in lieu of the actual name
'Note that the back slash added to the
'string before the file name because the code
'Application.ThisWorkbook.Path does not return the
'backslash at the end

strMyNewFolder = strThisWorkBookPath & "\Test folder"

MkDir mynewfolder

End Sub
--
Regards,

OssieMac


"Trish Smith" wrote:

> Hi,
>
> I was wondering if it would be possible to add subfolders to a folder using
> vba?
>
> If it is possible I would like to be able to add subfolders from a list of
> names in an Excel sheet.
>
> If anyone could help that would be great :-)
>
> Thank you
> --
> Trish

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      17th Aug 2008

Sub addsubfolders()

strfolder = "c:\temp"
Set fso = CreateObject _
("Scripting.FileSystemObject")
Set Myfolder = _
fso.GetFolder(strfolder)
RowCount = 1
Do While Range("A" & RowCount) <> ""
Newfolder = Range("A" & RowCount)
fso.createfolder (strfolder & "\" & Newfolder)
RowCount = RowCount + 1
Loop

End Sub

"Trish Smith" wrote:

> Hi,
>
> I was wondering if it would be possible to add subfolders to a folder using
> vba?
>
> If it is possible I would like to be able to add subfolders from a list of
> names in an Excel sheet.
>
> If anyone could help that would be great :-)
>
> Thank you
> --
> Trish

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question about subfolders with subfolders not opening when new mailarrives Stig Microsoft Outlook Discussion 0 24th Mar 2009 04:13 PM
Subfolders--Automatically moving emails into subfolders (Outlook 2 SLB Microsoft Outlook Discussion 2 11th Jan 2009 11:13 PM
Offline Files - Include all new subfolders but exclude selected subfolders? paulhetherington1@hotmail.com Windows XP Work Remotely 0 24th May 2006 09:23 AM
copy subfolders, replace text in files and save files in copied subfolders pieros Microsoft Excel Programming 0 1st Nov 2005 12:08 PM
Should subfolders be subfolders of inbox? Beemer Microsoft Outlook 8 24th Aug 2004 08:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:43 AM.