runningmusicman
New Member
- Joined
- Mar 22, 2018
- Messages
- 1
I need help as I have zero experience in VBA.
I have two columns of data, I am creating a folder titled Column A and a subfolder titled Column B. Now I want to take the name of the subfolder and search for it's corresponding project folder and replace the subfolder with a shortcuts folder to the actual project folder.
Here is what I have so far, minus a few lines it will create the folders and subfolders, but I failed at trying to do the shortcuts:
Sub Tester()
Const ROOT_FOLDER = "N:\Users\wdavis\QGIS\Sherburne County\Project Locations"
Const BASE_FOLDER = "N:\Projects Current"
Dim rng As Range, rw As Range, c As Range
Dim sPath, tmp, ProjPath As String
Dim i As Integer
Set rng = Selection
i = 1
For Each rw In rng.Rows
sPath = ROOT_FOLDER
bPath = BASE_FOLDER & "" & Cells(i, "B")
For Each c In rw.Cells
tmp = Trim(c.Value)
If Len(tmp) = 0 Then
Exit For
Else
sPath = sPath & tmp & ""
If Len(Dir(sPath, vbDirectory)) = 0 Then
ProjPath = Dir(bPath & " *", vbDirectory)
If (Len(ProjPath) > 1) Then
Cells(i, "B").Hyperlinks.Add Cells(i, "B"), ProjPath, TextToDisplay:=Cells(i, "B")
End If
End If
End If
Next c
i = i + 1
Next rw
End Sub
102103104105106107108109110111112114115116117118119120121122123124125126127128129130131132133vé7`ãW‚²PS€î²
I have two columns of data, I am creating a folder titled Column A and a subfolder titled Column B. Now I want to take the name of the subfolder and search for it's corresponding project folder and replace the subfolder with a shortcuts folder to the actual project folder.
Here is what I have so far, minus a few lines it will create the folders and subfolders, but I failed at trying to do the shortcuts:
Sub Tester()
Const ROOT_FOLDER = "N:\Users\wdavis\QGIS\Sherburne County\Project Locations"
Const BASE_FOLDER = "N:\Projects Current"
Dim rng As Range, rw As Range, c As Range
Dim sPath, tmp, ProjPath As String
Dim i As Integer
Set rng = Selection
i = 1
For Each rw In rng.Rows
sPath = ROOT_FOLDER
bPath = BASE_FOLDER & "" & Cells(i, "B")
For Each c In rw.Cells
tmp = Trim(c.Value)
If Len(tmp) = 0 Then
Exit For
Else
sPath = sPath & tmp & ""
If Len(Dir(sPath, vbDirectory)) = 0 Then
ProjPath = Dir(bPath & " *", vbDirectory)
If (Len(ProjPath) > 1) Then
Cells(i, "B").Hyperlinks.Add Cells(i, "B"), ProjPath, TextToDisplay:=Cells(i, "B")
End If
End If
End If
Next c
i = i + 1
Next rw
End Sub
102103104105106107108109110111112114115116117118119120121122123124125126127128129130131132133vé7`ãW‚²PS€î²