Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Creating Subfolders | Excel Programming | |||
Search through subfolders | Excel Programming | |||
SubFolders in macro | Excel Programming | |||
copy subfolders, replace text in files and save files in copied subfolders | Excel Programming | |||
Get list of subfolders | Excel Programming |