+ Reply to Thread
Results 1 to 29 of 29

Auto Create Hyperlinks to files on **

Hybrid View

  1. #1
    Registered User
    Join Date
    05-12-2011
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    22

    Auto Create Hyperlinks to files on **

    We have an excel document with many entries that correspond to individual files. The files are located in multiple sub-folders.

    Here is an example: {} indicate a column

    {A3} A1.1.1 PROCESS
    {A4} A1.1.1.1 PROCESS DESCRIPTION
    {A5} AD159-S00000-D-RPT-01231 {C5} PROCESS DESCRIPTION
    {A6} A1.1.1.2 DESIGN BASIS CRITERIA
    {A7} AD159-S00000-D-RPT-01227 {C7} BASIC ENGINEERING DESIGN DATA

    The bolded words are the actual folder structure.
    The non-bold is the actual file name minus the extension.
    The italic words are a description of that file.
    This permeates through the entire excel document. Some folders have over a 100 file names while others may only contain a few.

    There are over 6000 lines in the document. Is there ANY way to automate this process instead of clicking each individual line and hyper-linking them one by one.
    Last edited by kevin1010; 05-18-2011 at 12:59 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Auto Create Hyperlinks to files on **

    kevin1010,

    This could be automated with a macro, but the "folder structure" you have would be invalid. As in, A1.1.1 PROCESS is not a complete folder folder path. A complete folder path would look something like:

    C:\A\A1.1.1 PROCESS

    ~tigeravatar

  3. #3
    Registered User
    Join Date
    05-12-2011
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Auto Create Hyperlinks to files on **

    Quote Originally Posted by tigeravatar View Post
    kevin1010,

    This could be automated with a macro, but the "folder structure" you have would be invalid. As in, A1.1.1 PROCESS is not a complete folder folder path. A complete folder path would look something like:

    C:\A\A1.1.1 PROCESS

    ~tigeravatar
    You are correct about the complete folder path, I kind of figured we could just create a cell to auto add that in front of the path. Something like file:///...

    I do not know how to make the macro though. I am by no means an expert.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Auto Create Hyperlinks to files on **

    kevin1010,

    If you could post a sample workbook, I can create a macro to suit your needs

    ~tigeravatar

  5. #5
    Registered User
    Join Date
    05-12-2011
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Auto Create Hyperlinks to files on **

    omg, if you can figure this out, I'll have to buy you beer someday.

    This contains the first 30 lines... there are about 5600 total. Be aware there are other "main" sections. Like this one starts with Process. There is also electrical, mechanical, etc...
    Attached Files Attached Files

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Auto Create Hyperlinks to files on **

    kevin1010,

    I created a macro that should accomplish what you're looking for. Some notes about the macro:
    • Change FldrCol to the column that contains the folder and file information (it was column A in the sample workook)
    • Change StartRow to the row that the folder and file information starts on (it was row 3 in the sample workbook)
    • Change the strBasePath to the base folder that contains the listed folders and subfolders. Be sure to include the ending \

    Here's the code:
    Sub CreateLinks()
        
        Dim FldrCol As String:  FldrCol = "A"
        Dim StartRow As Long:   StartRow = 3
        
        Const strBasePath As String = "C:\Test Folder\" 'Be sure to include the ending \
        
        Application.ScreenUpdating = False
        Dim rngData As Range:   Set rngData = ActiveSheet.Range(FldrCol & StartRow, Cells(Rows.Count, FldrCol).End(xlUp))
        Dim aCell As Range, strTopFldr As String, strSubFldr As String, strFullPath As String
        For Each aCell In rngData
            If aCell.Interior.ColorIndex = 37 Then
                strTopFldr = aCell.Value & "\"
            ElseIf aCell.Font.Bold = True Then
                strSubFldr = aCell.Value & "\"
            Else
                strFullPath = strBasePath & strTopFldr & strSubFldr
                Dim FileFound As Boolean:   FileFound = False
                Dim CurrentFile As String:  CurrentFile = Dir(strFullPath)
                While CurrentFile <> vbNullString And FileFound = False
                    If InStr(1, CurrentFile, aCell.Value, vbTextCompare) > 0 Then
                        ActiveSheet.Hyperlinks.Add Anchor:=aCell, _
                                                   Address:=strFullPath & CurrentFile, _
                                                   TextToDisplay:=aCell.Value
                        FileFound = True
                    End If
                    CurrentFile = Dir()
                Wend
            End If
        Next aCell
        Application.ScreenUpdating = True
        
    End Sub


    Hope that helps,
    ~tigeravatar

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Auto Create Hyperlinks to files on **

    kevin1010,

    Forgot to mention something about the macro. In your sample workbook, the cell containing folder name "A1.1.1 PROCESS" was highlighted. The macro assumes all such folders are highlighted using that same color. The subfolders under that were bolded. The macro assumes all such subfolders are also bolded.

    Let me know if this is not the case or if you have any questions,
    ~tigeravatar

  8. #8
    Registered User
    Join Date
    05-12-2011
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Auto Create Hyperlinks to files on **

    Ok, you rock.

    That totally worked. It error'd out a few times but that is our fault. Some of the directory names don't exactly match up to the excel document. Can fix that.

    I have one more issue though...

    I noticed all the hyperlinks paths are relative right now to our network drive. But we will be handing this excel document with all the folder/files to our clients on **'s. Which means the drive letter and pathing will change a bit.

    I can copy the entire contents first to the ** and then run the macro... but what if the clients **-ROM drive isn't D:\
    There any fix to that?

    Also.. is there a way to tell it to not error out when it encounters a blank line? There are several throughout the document... its ok if not. We can just add n/a there and it works fine.

    Nuts... another thing. I need this macro to ignore all files except .pdf's. We have native .docs in there and it is hyperlinking some of those too.

    edit: umm ok... weird... it is **ing my letters C and D.
    Last edited by kevin1010; 05-13-2011 at 02:06 PM.

  9. #9
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Auto Create Hyperlinks to files on **

    Unfortunately you'd just have to change strBasePath to be whatever is needed. As an alternative, instead of using Const strBasePath As String = "C:\Test Folder\" you could instead do something like this:

    Dim strBasePath As String: strBasePath = ActiveSheet.Range("A1").Value
    Just change the Range("A1") to the cell that would contain that path (again, make sure the cell ends with the backslash). That way they can just update the cell to desired

    ~tigeravatar

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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