Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Add subfolders and name - Possible?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Add subfolders and name - Possible?

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Add subfolders and name - Possible?


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
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
Creating Subfolders MeTed Excel Programming 2 November 23rd 06 10:03 AM
Search through subfolders JustinP Excel Programming 4 September 5th 06 01:25 AM
SubFolders in macro pianoman[_4_] Excel Programming 2 April 28th 06 03:25 PM
copy subfolders, replace text in files and save files in copied subfolders pieros Excel Programming 0 November 1st 05 12:08 PM
Get list of subfolders Darren Hill[_3_] Excel Programming 3 March 6th 05 09:28 PM


All times are GMT +1. The time now is 02:20 PM.

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"