Automatically add hyperlinks when typing a serial number

AliKaffe

New Member
Joined
Aug 28, 2020
Messages
14
Office Version
  1. 2013
Platform
  1. Windows
Hello!
I work for a company that sells and services pumps.
I am attempting to make a excel sheet that will give us an overview of the pumps we service and sell.
I would like to make a macro that will automatically add a hyperlink to a file with the same file name on our server when i type the serial number in column L.
So i would like it to search the folder we put our Servicereports in, and add a hyperlink to the file if it finds a text in that column that matches the file name in the folder.
if possible i would also like it to search sub folders.
Is this possible?

if you see the image, i already added some hyper link manually. But would like this to happen automatically when i create a file in the folder with the same name.

tine.png
 
that fixed it! thank you. Also, if i add a new folder or file to the root folder, it seems i have to exit excel and open the file again to be able to find the file.
is that something wrong on my end? or is there a way to do this automatically too? or does it just take some time?
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
and another question.
i have a "pump card" that i want to do something similar with. (see attached image)
but i want to add reports automatically in the year and month columns. so, B-Q and 16-27.
2.png
 
Upvote 0
that fixed it! thank you. Also, if i add a new folder or file to the root folder, it seems i have to exit excel and open the file again to be able to find the file.
is that something wrong on my end? or is there a way to do this automatically too? or does it just take some time?

No, you're not doing anything wrong. The code is designed to fetch a list of files once per session. This is just a basic optimization that stores a list in memory, once, instead of rebuilding the list every time you add a link. There are a handful of approaches to rebuild your list:
  1. automatically - every time you add a new link (might be sluggish)
  2. on demand - by way of a keyboard shortcut, button, etc.
  3. creating a file system watcher - over-done perhaps, but probably the most elegant solution thus far (and, of course, the more complicated)
  4. other ways I'm sure
Number 2 is probably a good choice.

_______________________________________________________________________________________________________________________________________________________________________

and another question.
i have a "pump card" that i want to do something similar with. (see attached image)
but i want to add reports automatically in the year and month columns. so, B-Q and 16-27.

Where are you getting your month and year information? I don't see any info in your image that relates to time.
 
Upvote 0
and another question.
i have a "pump card" that i want to do something similar with. (see attached image)
but i want to add reports automatically in the year and month columns. so, B-Q and 16-27.

Where are you getting your month and year information? I don't see any info in your image that relates to time.
 
Upvote 0
we usually just make a word file named 2020.08.28, so would be same function as the first code i guess. just for B-Q columns and 16-27 Rows.
Adding a button to update with would be enough.
 
Upvote 0
No, you're not doing anything wrong. The code is designed to fetch a list of files once per session. This is just a basic optimization that stores a list in memory, once, instead of rebuilding the list every time you add a link. There are a handful of approaches to rebuild your list:
  1. automatically - every time you add a new link (might be sluggish)
  2. on demand - by way of a keyboard shortcut, button, etc.
  3. creating a file system watcher - over-done perhaps, but probably the most elegant solution thus far (and, of course, the more complicated)
  4. other ways I'm sure
Number 2 is probably a good choice.

_______________________________________________________________________________________________________________________________________________________________________



Where are you getting your month and year information? I don't see any info in your image that relates to time.

This one?
i am not quite sure i understand.
3.png


Here you can see i have a row with years, and a column with months. I basically just want to add hyperlinks to our report files ( word document) automatically when i type the file name. i have done this manually in this sheet as you can see.
 
Upvote 0
can someone help me with the on demand update code? this is the only thing missing now.
 
Upvote 0
Sorry Ali. I missed your reply. Must have deleted the email with my third thumb. The only thing you need to change is this procedure.

VBA Code:
Public Sub TryAddLink(Optional ByVal Target As Range = Nothing)
    Static d As Dictionary
    Dim fso As New FileSystemObject
  
    If Target Is Nothing Then
        Set d = Nothing
        Exit Sub
    End If
  
    If d Is Nothing Then
        Set d = New Dictionary
        'change to root.
        GetFileList fso.GetFolder(Parent.Path & "\Root"), d
    End If
  
    If d.Exists(Target.Text) Then Target.Hyperlinks.Add Target, d(Target.Text)
End Sub

SImply call TryAddLink without passing an argument and it will rebuild the file list the next time you make an entry. You may assign this to a button or keyboard shortcut.
I update your example.
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top