HELP - Creating Folder and Hyperlinking in EXCEL using VBA

daleseng

New Member
Joined
May 16, 2017
Messages
1
Morning,


I have next to zero VBA training, what i have is a previous colleague had created a worksheet with automatic hyperlinking that created a folder structure within a shared drive.


We are making a new sheet and i'm trying to use the same code for the new sheet. After spending the past few days working on it i think i'm almost there on creating folders, but for some reason the hyper link is not working..


see code below, the error is highlighting the part "ActiveSheet.Hyperlinks.Add Anchor:=Range("B" & i), Address:=dir"






Sub Worksheet_SelectionChange(ByVal Target As Range)


Dim R As Range
Dim RootFolder As String
RootFolder = "S:\1A - Dales OR PMS\1 - Dales OR Estimating"
For Each R In Range("B7:B56")
If Len(R.Text) > 0 Then
On Error Resume Next
MkDir RootFolder & "" & R.Text
MkDir RootFolder & "" & R.Text & "\01 - Clients Docs"
MkDir RootFolder & "" & R.Text & "\02 - DESOR Estimate Docs"
MkDir RootFolder & "" & R.Text & "\03 - Sub-Contractors Docs"
MkDir RootFolder & "" & R.Text & "\04 - Drawings"
MkDir RootFolder & "" & R.Text & "\05 - Technical"
MkDir RootFolder & "" & R.Text & "\06 - Photos"
MkDir RootFolder & "" & R.Text & "\07 - Emails"
MkDir RootFolder & "" & R.Text & "\08 - Material Costs"
On Error GoTo 0
End If
Next R




Dim cnf
Dim dir As String
Dim fnsh As Long
Dim i As Long
Set cnf = CreateObject("Scripting.FileSystemObject")
fnsh = ActiveSheet.Cells(ActiveSheet.Rows.Count, "B").End(xlUp).Row
Application.ScreenUpdating = False
For i = 4 To fnsh
dir = "S:\1A - Dales OR PMS\1 - Dales OR Estimating" & Range("A" & i).Value
If Not cnf.FolderExists(dir) Then
cnf.CreateFolder (dir)
End If
'Range("B" & i).Hyperlinks.Delete
ActiveSheet.Hyperlinks.Add Anchor:=Range("B" & i), Address:=dir
Next
Set cnf = Nothing
Application.ScreenUpdating = True
End Sub


any info at all would be appreciated! this is my first time here so if i have posted this in the wrong place or not included enough information please let me know.


Thanks


Joe
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top