Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HOW DO I USE EXCEL TO CREATE FILEs AND FOLDERS FROM A TEMPLATE?

I have a folder structure with template files in the folders. I want to
create a named folder (based on a sequential number), all subfolders and
copies of the template files with the same suffix that the top level folder
has (in this case, a -xxx number). I want to do this from a command within
excel, then create a new column based on the new folders (with contract
number/name/filename) and set hyperlinked cells within the new column to the
newly created files. I would also like to password protect the macro/command
to ensure it cannot be accessed accidentally.

Any help greatly appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default HOW DO I USE EXCEL TO CREATE FILEs AND FOLDERS FROM A TEMPLATE?

See if this works. I modified some previously written macro(s). You need to
change the BaseFolder (root file where template is located and where new
folder will be created), TemplateFolder (you template directory), and the New
Column letter. the code searches all sub-directories in the Basefolder.

Sub Copyfolder()

Basefolder = "C:\Temp"
TemplateFolder = "Test"

Set FSO = CreateObject _
("Scripting.FileSystemObject")

MyNumber = InputBox("Enter a New Contract Number")
NewFolderName = Basefolder & "\" & TemplateFolder & "-" & MyNumber

FSO.Copyfolder _
Basefolder & "\" & TemplateFolder, NewFolderName

RowCount = 1
NewColumn = "A"
'rename all files and folders
Call GetSubFolder(NewFolderName + "\", MyNumber, NewColumn, RowCount)
End Sub

Sub GetSubFolder(strFolder, MyNumber, NewColumn, ByRef RowCount)
Set FSO = CreateObject _
("Scripting.FileSystemObject")

Set Folder = _
FSO.GetFolder(strFolder)

If Folder.subfolders.Count 0 Then
For Each sf In Folder.subfolders
On Error GoTo 100
Call GetSubFolder(strFolder + sf.Name + "\", _
MyNumber, NewColumn, RowCount)
ParentFld = FSO.GetParentFolderName(Folder)
NewName = strFolder & sf.Name & "-" & MyNumber
FSO.MoveFolder sf, NewName
Range(NewColumn & RowCount) = NewName
Range(NewColumn & RowCount).Hyperlinks.Add _
Anchor:=Range(NewColumn & RowCount), _
Address:=NewName, _
TextToDisplay:=NewName
RowCount = RowCount + 1
100 Next sf
End If
'folder size in bytes
On Error GoTo 200
For Each fl In Folder.Files

Base = FSO.getbasename(fl)
NewName = Folder & "/" & Base & "-" & _
MyNumber & "." & FSO.getextensionname(fl)

FSO.MoveFile fl, NewName
Range(NewColumn & RowCount) = NewName
Range(NewColumn & RowCount).Hyperlinks.Add _
Anchor:=Range(NewColumn & RowCount), _
Address:=NewName, _
TextToDisplay:=NewName
RowCount = RowCount + 1

Next fl

200 On Error GoTo 0

End Sub







"mabright" wrote:

I have a folder structure with template files in the folders. I want to
create a named folder (based on a sequential number), all subfolders and
copies of the template files with the same suffix that the top level folder
has (in this case, a -xxx number). I want to do this from a command within
excel, then create a new column based on the new folders (with contract
number/name/filename) and set hyperlinked cells within the new column to the
newly created files. I would also like to password protect the macro/command
to ensure it cannot be accessed accidentally.

Any help greatly appreciated.

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
Macro to create multi files from a template with different data [email protected] Excel Discussion (Misc queries) 1 August 28th 08 04:04 PM
Create folders from excel Boss Excel Programming 2 March 7th 08 03:46 PM
Create Folders From Excel WBTKbeezy Excel Programming 4 November 28th 07 03:07 PM
Create folders in Window Explorer from tab or csv files export kricketts Excel Worksheet Functions 1 March 27th 06 09:01 PM
Can anyone help me Create Excel list of files in windows folders solrac1956 Excel Worksheet Functions 1 November 28th 05 11:07 PM


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

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

About Us

"It's about Microsoft Excel"