+ Reply to Thread
Results 1 to 9 of 9

Modify Macro Formula - Auto Hyperlink Selected Cells

  1. #1
    Registered User
    Join Date
    07-02-2011
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    10

    Modify Macro Formula - Auto Hyperlink Selected Cells

    Hi All,

    I found this VBA code, would appreciate if this code can be adjusted.

    Let say I have my excel file in different folder location, (i.e. D: drive) and the files to be hyperlink are in Local server (F: Drive = shared network "Mapped") and should search through several sub-folder (i.e. Drawings, Documents and Models)

    Also, if the name in excel is NO MATCH found in the folders should NOT hyperlink. For me to find out if there are missing files.

    Any help is very much appreciated.


    Sub Add_Hyperlinks()
    Dim c As Range
    Dim sAddress As String

    For Each c In Selection
    If c <> "" Then
    sAddress = "PDFS" & _
    Replace(c.Text, " ", "") & ".pdf"
    c.Parent.Hyperlinks.Add _
    Anchor:=c, Address:=sAddress, _
    TextToDisplay:=c.Text
    End If
    Next c

    End Sub

    Thanks,
    Mielkew

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Modify Macro Formula - Auto Hyperlink Selected Cells

    1. Please edit your previous post by adding code tags around your code
    (click on Edit Post,select the VBA text, and click on the # icon)
    2. What is currently included in the cell text - does it include the current file path or only the text to build up the file name?
    thanks
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Modify Macro Formula - Auto Hyperlink Selected Cells

    I have assumed that your selected cells contain the file name (including extension) and not the path

    - if this is not a correct assumption then amend the 2 lines
    Please Login or Register  to view this content.
    to build your string differently - perhaps this (??)
    Please Login or Register  to view this content.

    Also amend this line
    Please Login or Register  to view this content.
    to include a list of your main folders to search (VBA will also search all their subfolders)
    - include each path in " " and separated by commas


    To run the macro :Select your cells and run sub AddLinks


    The code will not work unless VBA Reference is added for Microsoft Scripting Runtime

    VBA References.jpg

    VBA References Scripting Runtime.jpg

    This code should be placed in a General module.
    Please Login or Register  to view this content.
    Last edited by kev_; 04-19-2017 at 03:52 AM.

  4. #4
    Registered User
    Join Date
    07-02-2011
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Modify Macro Formula - Auto Hyperlink Selected Cells

    Hi Kev,

    Thanks for your response but I think I'm not doing it right!

    The file name in excel does not contain any file extension. i.e. CP1-SDW-ME-00001

    PDF Files Folder Location: F:\COMPANY\PROJECTS\TDO-18-TTC-0019\DESIGN DATA\01_SCHEMATIC DESIGN\IRSD#1 - 17-Jan-17\Drawings or Documents or Model
    Subfolders under 17-Jan-17 Folder are: Drawings, Documents, Model - I want this code to search particular in these folder location.

    Excel File Location: Z:\COMPANY\12.DOC-CONTROL\EDRMS\Master Log - Technical Submittal

    The Microsoft Scripting Runtime is Activated - I think this is the only one I got right!

    Thanks,
    Mielkew


    Please Login or Register  to view this content.
    Last edited by mielkew27; 04-19-2017 at 06:24 AM.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Modify Macro Formula - Auto Hyperlink Selected Cells

    I will look at this for you shortly
    In the meantime, please click EDIT on your previous post and put code tags around your code
    (select your code and then click on # icon)
    thanks
    Last edited by kev_; 04-19-2017 at 06:21 AM.

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Modify Macro Formula - Auto Hyperlink Selected Cells

    That was easy. I posted your code into a clean file and with a minor modification it worked
    I apologise -I forgot to tell you to amend the lines that check for each name (to match what you amended in building up the link address)

    This needs amending on BOTH lines (to add the ".pdf" extension)
    Please Login or Register  to view this content.
    If it still does not work then look at the message box (returned by the line below) to confirm that the file name matches exactly with the actual file name in the folder
    Please Login or Register  to view this content.
    Insert this line immediately below this line
    Please Login or Register  to view this content.
    After you get it working for one folder I will help you tailor it to search all the specific folders you want
    Last edited by kev_; 04-19-2017 at 06:28 AM.

  7. #7
    Registered User
    Join Date
    07-02-2011
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Modify Macro Formula - Auto Hyperlink Selected Cells

    Hi Kev,

    I think the code is working now but the files are not opening. As you can see in the excel list only those files that matched has the hyperlink.

    I did insert this Code
    Please Login or Register  to view this content.
    After this line but I'm getting an error.
    Please Login or Register  to view this content.
    This is the Code I'm using now, sorry I really don't have any knowledge about VBA coding:
    Please Login or Register  to view this content.
    Attached Images Attached Images
    Last edited by mielkew27; 04-19-2017 at 08:20 AM.

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Modify Macro Formula - Auto Hyperlink Selected Cells

    Replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-02-2011
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Modify Macro Formula - Auto Hyperlink Selected Cells

    Thanks, Kev! Cheers


    Quote Originally Posted by kev_ View Post
    Replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. macro for auto creating folders from selected cells
    By 9d1awd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2014, 10:58 PM
  2. excel macro to modify Hyperlink to copy and paste
    By jffwright82 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2014, 03:55 PM
  3. [SOLVED] Modify insert rows macro if out if selected range
    By kstrick99999 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-07-2012, 11:31 AM
  4. copying selected cells formula in macro
    By clundeen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2011, 06:09 AM
  5. apply formula to selected cells via macro
    By Axe in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2009, 11:19 AM
  6. modify all selected cells
    By Smed in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-05-2008, 09:50 AM
  7. Auto-fill the selected cells without using macro
    By sachi.b@gmail.com in forum Excel General
    Replies: 3
    Last Post: 02-22-2006, 11:35 PM
  8. Modify a Macro to Repeat for all Selected Worksheets
    By carl in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-12-2006, 01:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1