Hi there,
I have code that works really well except for one thing... The is a trim command in the code I used and I would like to remove it but I keep getting out of range or syntax errors.
the issue part:
folder = Trim(Split(Target.TextToDisplay, " ")(1))
When it created the folder it only takes the first word in the string and I would prefer the whole string in the folder name.
complete script:
Public Sub Create_Folder_and_Link(ByVal Target As Hyperlink)
Dim folder As String
'Extracts folder name XXXXX from the TextToDisplay string which has the format "Create XXXXX folder"
folder = Trim(Split(Target.TextToDisplay, " ")(1))
If Right(MAIN_FOLDER, 1) = "" Then
folder = MAIN_FOLDER & folder & ""
Else
folder = MAIN_FOLDER & "" & folder & ""
End If
'Create folder if it doesn't exist
If Dir(folder, vbDirectory) = "" Then MkDir folder
If Dir(folder & "01_Reference_Info", vbDirectory) = "" Then MkDir folder & "01_Reference_Info"
If Dir(folder & "02_Work", vbDirectory) = "" Then MkDir folder & "02_Work"
If Dir(folder & "02_Work\01_CAD", vbDirectory) = "" Then MkDir folder & "02_Work\01_CAD"
If Dir(folder & "02_Work\02_Documents", vbDirectory) = "" Then MkDir folder & "02_Work\02_Documents"
'If Dir(folder & "03_CAD", vbDirectory) = "" Then MkDir folder & "03_CAD"
'Add in column F cell the hyperlink which opens this folder
With Worksheets(Target.Range.Parent.Name)
.Hyperlinks.Add anchor:=.Cells(Target.Range.Row, "G"), Address:=folder, TextToDisplay:="Open " & folder
End With
End Sub
I see why, but don't know how to take the string completely. Any help would be appreciated...
Kip
I have code that works really well except for one thing... The is a trim command in the code I used and I would like to remove it but I keep getting out of range or syntax errors.
the issue part:
folder = Trim(Split(Target.TextToDisplay, " ")(1))
When it created the folder it only takes the first word in the string and I would prefer the whole string in the folder name.
complete script:
Public Sub Create_Folder_and_Link(ByVal Target As Hyperlink)
Dim folder As String
'Extracts folder name XXXXX from the TextToDisplay string which has the format "Create XXXXX folder"
folder = Trim(Split(Target.TextToDisplay, " ")(1))
If Right(MAIN_FOLDER, 1) = "" Then
folder = MAIN_FOLDER & folder & ""
Else
folder = MAIN_FOLDER & "" & folder & ""
End If
'Create folder if it doesn't exist
If Dir(folder, vbDirectory) = "" Then MkDir folder
If Dir(folder & "01_Reference_Info", vbDirectory) = "" Then MkDir folder & "01_Reference_Info"
If Dir(folder & "02_Work", vbDirectory) = "" Then MkDir folder & "02_Work"
If Dir(folder & "02_Work\01_CAD", vbDirectory) = "" Then MkDir folder & "02_Work\01_CAD"
If Dir(folder & "02_Work\02_Documents", vbDirectory) = "" Then MkDir folder & "02_Work\02_Documents"
'If Dir(folder & "03_CAD", vbDirectory) = "" Then MkDir folder & "03_CAD"
'Add in column F cell the hyperlink which opens this folder
With Worksheets(Target.Range.Parent.Name)
.Hyperlinks.Add anchor:=.Cells(Target.Range.Row, "G"), Address:=folder, TextToDisplay:="Open " & folder
End With
End Sub
I see why, but don't know how to take the string completely. Any help would be appreciated...
Kip