+ Reply to Thread
Results 1 to 14 of 14

VBA to automatically Hyperlink cell text with similar file name

  1. #1
    Registered User
    Join Date
    11-19-2015
    Location
    india
    MS-Off Ver
    2013
    Posts
    10

    Post VBA to automatically Hyperlink cell text with similar file name

    hi,
    i currently have an excel sheet where i am entering the issued certificates for the jobs done.
    Some examples for the certificate names are
    JAN18/161/C1-C10
    FEB18/185/C1
    FEB18/190/C1 & FEB18/190/MPI/C1

    I have similar names for the files that i save. But the problem is that as windows does not accept "/" in the file name i have replaced "/" with "." in the file names and they look like
    JAN18.161.C1-C10.pdf
    FEB18.185.C1.pdf
    FEB18.190.C1 & FEB18.190.MPI.C1.pdf

    It would be very difficult for me to link them manually, as there are alot of jobs. And there are not just certificates that i have to deal with. i have invoice, quotation, delivery notes with the same requirement.

    Now i want to be able to click the cell with certificate name text and i want the file to open.
    And i want the hyperlinks to update automatically as i put the certificate name. if there is no file with that name it should stay as plain text.
    It would be easier if the color for the certificate name text can change when it gets hyperlinked so that it becomes easier to identify that it has been linked.

  2. #2
    Registered User
    Join Date
    11-19-2015
    Location
    india
    MS-Off Ver
    2013
    Posts
    10

    Re: VBA to automatically Hyperlink cell text with similar file name

    can someone please help me with this?

  3. #3
    Registered User
    Join Date
    10-01-2016
    Location
    Chennai, India
    MS-Off Ver
    2007
    Posts
    5

    Re: VBA to automatically Hyperlink cell text with similar file name

    Hi Ahmed,

    Just try to replace "." with "/" in your code

    you can use the Replace() function. [a = Replace("JAN18.161.C1-C10", ".", "/")]

    You can set the file name to string and try replacing


    Hope this works,

    Best Regards,
    Hussain

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA to automatically Hyperlink cell text with similar file name

    I am assuming that your data is in column A of Sheet1. Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your Sheet1 and click 'View Code'. Paste the macro into the empty code window that opens up. In the code, change the path (C:\Test\) to the folder containing your files to suit your needs. Close the code window to return to your sheet. Click on a cell in column A.
    Please Login or Register  to view this content.
    Last edited by Mumps1; 02-10-2018 at 03:01 PM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  5. #5
    Registered User
    Join Date
    11-19-2015
    Location
    india
    MS-Off Ver
    2013
    Posts
    10

    Re: VBA to automatically Hyperlink cell text with similar file name

    Quote Originally Posted by Mumps1 View Post
    I am assuming that your data is in column A of Sheet1. Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your Sheet1 and click 'View Code'. Paste the macro into the empty code window that opens up. In the code, change the path (C:\Test\) to the folder containing your files to suit your needs. Close the code window to return to your sheet. Click on a cell in column A.
    Please Login or Register  to view this content.
    The code is perfect. but there are a few issues i am encountering while using this.
    A single mouse click or even using the arrow keys to move to the cell is opening the file. if i want to edit a cell, at first the hyperlinked file opens and then i will be able to edit the file. this is happening with empty cells aswell. so if the hyperlinked cells could be opened via another method it would be easy. something like "ctrl+left mouse click".
    If the cell is empty and i try to add text to it i get an error at first and then i have to exit it and enter again. "run-time error '-2147221014 (800401ea)': cannot open the specified file"

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA to automatically Hyperlink cell text with similar file name

    I've changed the code to a Worksheet_BeforeDoubleClick event. This simply means that now you have to double click the cell in column A instead of just selecting it.
    Please Login or Register  to view this content.
    If you use this version, you simply right click the cell:
    Please Login or Register  to view this content.
    Take your pick!

  7. #7
    Registered User
    Join Date
    11-19-2015
    Location
    india
    MS-Off Ver
    2013
    Posts
    10

    Re: VBA to automatically Hyperlink cell text with similar file name

    Quote Originally Posted by Mumps1 View Post
    I've changed the code to a Worksheet_BeforeDoubleClick event. This simply means that now you have to double click the cell in column A instead of just selecting it.
    Please Login or Register  to view this content.
    If you use this version, you simply right click the cell:
    Please Login or Register  to view this content.
    Take your pick!
    sorry for the late reply. had a very busy week. did not get time to check till today.
    this macro has become more effective now. could you please add some additional code to stop it from throwing an error when an empty cell is called or when a cell with no file to be linked is called.

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA to automatically Hyperlink cell text with similar file name

    Try one of these macros:
    Please Login or Register  to view this content.
    Change the folder path to suit your needs.

  9. #9
    Registered User
    Join Date
    11-19-2015
    Location
    india
    MS-Off Ver
    2013
    Posts
    10

    Re: VBA to automatically Hyperlink cell text with similar file name

    now this is way better. but can you modify the code so that the cell that is not linked does not change the font color to red. As of now the font color of the cell is changing to red if the file is hyperlinked or not. i would like the color to change for only those cells who have successfully been hyperlinked.
    thank you so much for the help. it was very difficult linking almost 1100 cells manually.

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA to automatically Hyperlink cell text with similar file name

    Sorry. I should have picked up on that myself.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-19-2015
    Location
    india
    MS-Off Ver
    2013
    Posts
    10

    Re: VBA to automatically Hyperlink cell text with similar file name

    this code is perfect now. thank you so much Mumps1 for the help. i had made a same thread on 2 different forums before i posted here, but no replies yet.
    thank you once again

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA to automatically Hyperlink cell text with similar file name

    You are very welcome. Since you posted the same question on 2 other forums, could I suggest that in those threads, you post a link to this thread. Forums of this nature require that you do this when you cross-post your question on more than one forum. This will prevent other people from spending time trying to find a solution to a problem that has already been solved.

  13. #13
    Registered User
    Join Date
    11-19-2015
    Location
    india
    MS-Off Ver
    2013
    Posts
    10

    Re: VBA to automatically Hyperlink cell text with similar file name

    done. thank you once again for all the help

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: VBA to automatically Hyperlink cell text with similar file name

    My pleasure.

+ 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. How to print the file in the hyperlink automatically
    By reimar_rem in forum Excel General
    Replies: 4
    Last Post: 01-23-2018, 02:20 AM
  2. [SOLVED] How to Enter Name of File and Automatically Turn It Into Hyperlink to Said File
    By Pheonix843 in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 04-02-2016, 02:37 AM
  3. Replies: 12
    Last Post: 06-02-2014, 01:45 PM
  4. [SOLVED] Run a recorded macro on one text file on a another similar file.
    By eranha in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-01-2013, 03:48 PM
  5. Automatically hyperlink to file without knowing extension
    By lozoroo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-24-2013, 10:00 AM
  6. [SOLVED] Hyperlink in excel spreadsheet to email file automatically
    By sparker717 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2006, 06:10 PM
  7. Macro to Copy Hyperlink to another file as a HYPERLINK, not text...
    By dollardoc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2005, 08:07 PM

Tags for this Thread

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