Hi and thanks for looking at my thread.
I have the following VBA which works to a point, however it is running slow.
It creates a New subfolder within a Folder based on cell value in column C.
I would like it to start from "C3" Down. (not quite sure how to get it there)
then it creates a word document and places that inside the newly created folder, then creates a hyperlink to the folder.
I have pieced the vba together more through trial and error.
Trial.xls
Private Sub Worksheet_Change(ByVal Target As Range)
Dim varDoc As Object
Dim endRow As Long
Dim Rng As Range, c As Range
Dim FilePath, currPath As String
Application.EnableEvents = False
endRow = Cells(ActiveSheet.Rows.Count, 3).End(xlUp).Row ''Find end row in column C
Set Rng = Range(Cells(3, 3), Cells(endRow, 3)) ''check each used cell in column C
For Each c In Rng '' For each cell in range
If c.Value <> vbNullString And c.Hyperlinks.Count = 0 Then ''test to see if cell not empty and no hyperlink to speed loop up
''Test to see if file exists and create on if it doesn't
currPath = ThisWorkbook.Path
If currPath = vbNullString Then currPath = "C:\Users\Downloads\Tracker" & Cells(c.Row, 3).Value ''save folder to desktop if file isn't saved
folderExists currPath, Cells(c.Row, 3).Value
FilePath = currPath & "\" & Cells(c.Row, 3).Value
Set varDoc = CreateObject("Word.Application")
varDoc.Visible = True
ActiveSheet.Cells(c.Row, 3).Copy
varDoc.Documents.Add
varDoc.Selection.Paste
varDoc.ActiveDocument.SaveAs FileName:=FilePath & "\" & Cells(c.Row, 3).Value
'create directories if needed
Call MakeFolders(currPath)
''if the folder wasn't found and one was created in the folderExists function, add a hyperlink
ActiveSheet.Hyperlinks.Add Anchor:=c, Address:=currPath & "\" & Cells(c.Row, 3).Value, TextToDisplay:=c.Value
Else: End If
Next c
Set Rng = Nothing
Application.EnableEvents = True
End Sub
The 2nd part of the code is written by Jerry Beaucaire
and works fine (as you would expect)
Function MakeFolders(MyStr As String)
'Author: Jerry Beaucaire
'Date: 7/14/2010
'Summary: Create directories and subdirectories based
' on the text strings fed to the function
' This version is to be called by other macros
Dim MyArr As Variant
Dim pNum As Long
Dim pBuf As String
On Error Resume Next
MyArr = Split(MyStr, "\")
pBuf = MyArr(LBound(MyArr)) & "\"
For pNum = LBound(MyArr) + 1 To UBound(MyArr)
pBuf = pBuf & MyArr(pNum) & "\"
MkDir pBuf
Next pNum
End Function
I look forward to any help or direction
Bookmarks