Sunday, August 18, 2019

VBA Macros: Create Hyperlink for filenames or folder names fro...

Source URL:VBA Macros: Create Hyperlink for filenames or folder names fro...:



Here is a easy way to solve my problem.

I create a hyper link in excel to only the specific sub folders which i have to check and open them by clicking the hyperlink.


Note: Please take care that the the list of folder names you want to create hyperlink is present in "Sheet1" and in Column "A" or else you can modify the code according to your need.
Provide the Main folder path in the Input Box when it pop ups.

For any assistance please post me.

Here is the code for hyperlinking.

****************************************************************
Code:
****************************************************************
Sub Create_Hyperlink()

Dim Path As String
Dim lastRow As Long
Dim rOffset As Long
Dim partialPath As String
Dim linkPath As String

Path = InputBox("Please paste the path to which the list should be hyperlinked")
 
  Const SheetToPutLinksOn = "Sheet1"
  Const ColumnWithFileNames = "A"
  Const firstFilenameRow = 1

  ThisWorkbook.Worksheets(SheetToPutLinksOn).Activate
  Application.ScreenUpdating = True
  partialPath = Path & "\"
  lastRow = Range(ColumnWithFileNames & Rows.Count).End(xlUp).Row - _
   firstFilenameRow
  Range(ColumnWithFileNames & firstFilenameRow).Select
  Application.ScreenUpdating = True
  For rOffset = 0 To lastRow
     If Not IsEmpty(ActiveCell.Offset(rOffset, 0)) Then
      linkPath = partialPath & ActiveCell.Offset(rOffset, 0).Text
      ActiveSheet.Hyperlinks.Add anchor:=ActiveCell.Offset(rOffset, 0), _
       Address:=linkPath
    End If
  Next
  ThisWorkbook.Saved = True
  Application.ScreenUpdating = True

End Sub

****************************************************************

No comments:

Post a Comment

This is the comment from the message:

Note: Only a member of this blog may post a comment.

Featured Post

Best-Brief-Resume

BEST BRIEF RESUME