Using MkDir and then populating Hyperlink using Add Method

Gkr1981

New Member
Joined
Feb 9, 2010
Messages
46
Hi All,

I have been searching for the past few hours and trying a multitude of different items for such a simple task and its just not playing ball.

What i want to do is the following

I have a cell named ListingFolder - the contents of cell is a formula which displays the directory name i want to create its a simple "C:\ & B1 & B2" to get me the folder name i want created.

1. When trying to use MkDir with that value as a string it doesnt create the folder, so i have to manually specify in the formula

Code:
MkDir "C:\" & [b6] & " " & [b7]

But im hoping to get it so it would just read the name of the cell so the spreadsheet can be dynamic and not require people to edit items in vba

The second part of the macro what i need it to do is to create a Hyperlink to that new Folder in a Cell

I have tried using the Hyperlink Add Method, but it is causing nothing but errors mostly "Path Not Found, even though the folder has been created.

If someone can assist me with fixing the MkDir piece to use a cell value as the file directory, and then help me create a hyperlink to that folder.

I would be forever greatful.

Cheers
G
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
To create folder C:\Test Folder

B6 value Test
B7 value Folder

and your code
Code:
    MkDir "C:\" & [b6] & " " & [b7]

Multiple levels - a folder MUST be created BEFORE creating its sub-folders
example: create folder C:\XXX\ABC (where C:\XXX does not yet exist), with B6 = XXX and B7 = ABC

Code:
    MkDir "C:\" & [b6]
    MkDir "C:\" & [b6] & "[B]\[/B]" & [b7]
 
Last edited:
Upvote 0
Hi Yongle,

The problem isn't creating subfolders.

The problem there is trying to get a CEll to have the full folder name I want to create instead of using hardcoded directory links.

And then the issue is of it not allowing me to Hyperlink the address.

Appreciate the feedback.

Cheers
Graeme
 
Upvote 0
Try this macro. It creates the link in B3.

Code:
Public Sub Create_Folder_and_Link()
        
    With Range("ListingFolder")
        If Dir(.Value, vbDirectory) = vbNullString Then
            MkDir .Value
        End If
        .Worksheet.Hyperlinks.Add Anchor:=.Worksheet.Range("B3"), Address:=.Value, TextToDisplay:="Link to ListingFolder"
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,319
Members
449,218
Latest member
Excel Master

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