+ Reply to Thread
Results 1 to 2 of 2

Macro Hyperlinking Many Files in a Directory

  1. #1
    Registered User
    Join Date
    06-06-2016
    Location
    U.K
    MS-Off Ver
    2013
    Posts
    4

    Macro Hyperlinking Many Files in a Directory

    Hello

    I have thousands of reports that I wish the user to be able to access via hyper link in an excel sheet.

    In the sheet, the report reference number is found in B3: the end of the sheet. I wish the hyper links to be created in C3 onwards.

    The reports themselves feature a standard naming convention - "BA #XX".

    I want the macro to search in a directory for the part of the text in B3 (wildcard?), and then hyperlink to the file that it finds the match to.

    I have started working on this - and came up with this.

    Sub update_links()

    Dim start_path As String
    Dim file_to_find As String
    Dim iRow As Integer
    Dim iCol As Integer

    iRow = 3 'change to 3 if there are headers
    iCol = 2 'Column B

    start_path = "P:\Engineering\Lab Analysis\Analysis Records" & "\"
    analysis_number = ActiveSheet.Range("B" & iRow).Text

    file_to_find = analysis_number & "*"

    DirFile = Dir(start_path & file_to_find, vbDirectory)

    Do While ActiveSheet.Cells(iRow, iCol).Value <> ""

    analysis_path = start_path & DirFile

    ActiveSheet.Range("B" & iRow).Hyperlinks.Add Anchor:=ActiveSheets.Range("C" & iRow), _
    Address:=analysis_path, TextToDisplay:="Link"

    'move to the next row
    iRow = iRow + 1
    Loop

    End Sub




    I am still not very proficient with VBA, but I am trying to learn. I keep receving error 424 "Object Required" - I can't see what the problem is with the code.

    Any insight would be great.

    Thanks.

    PS I am not exactly sure on the DirFile function - i read another piece of code as inspiration however I dont know if i implemented it correctly.

    Thanks.

  2. #2
    Registered User
    Join Date
    06-06-2016
    Location
    U.K
    MS-Off Ver
    2013
    Posts
    4

    Re: Macro Hyperlinking Many Files in a Directory

    Anyone, would really appreciate it

+ 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. Hyperlinking from a Form Input Based on Directory
    By nKife in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-06-2015, 06:51 PM
  2. [SOLVED] Macro to Import Multiple TXT Files into workbook - User to select files/directory
    By saber007 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-15-2013, 08:43 PM
  3. Macro to get list of all files in directory
    By boss1982 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-21-2013, 03:18 PM
  4. Macro to Move files from one directory to other directory
    By Shanthuday in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2013, 07:21 AM
  5. Macro to go thru directory of Excel files
    By stvgarner in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-06-2011, 06:13 PM
  6. Apply macro to many files in given directory
    By dversa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-16-2010, 11:51 AM
  7. Macro to move files from one directory to another
    By Barb Reinhardt in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-21-2006, 12:40 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