PDA

View Full Version : [SOLVED:] Change links that match or have part of path



nmgmarques
01-31-2017, 09:33 AM
Hi all. I have a small issue here I can't solve any other way and was hoping that maybe this could be solved with VBA. Here's the problem:

Working in a corporate environment, some users work on Network Computers, other on Local Computers. The guys on NC's send the LC's links via Outlook form time to time and the links are formatted as in the example:

\\company.biz\data01\DepData\ptcbr\RH\_data\2017\Horários de Trabalho\Rev. 23\2 - Horários de Trabalho Rev 23_distribuição_01_2017.xlsx

Now here's the problem... That data01 bit... Only works for the NC's. For some reason we still haven't figured out the LC's can't connect to the shares when going through data01. However, we have managed to get the LC's connected using data99 instead. So each time we get a link, we cannot click it but rather copy it, change 01 to 99 and then open the file or link in question. Stranger still, both data01 and data99 work on the NC's. But that's beside the point.

My question here, is there any way to have Outlook check a clicked link for \\company.biz\data01\(...) and if it exists, replace it with \\company.biz\data99\(...), without making changes to all other links to webpages and sorts?

I hope I was clear enough. If not, please let me know and I'll try to give better info and examples. Help greatly appreciated.

skatonni
01-31-2017, 02:25 PM
This switches the text and opens the link with Windows Explorer. You do not click on the link, just open the item.


Option Explicit

Private Sub HyperlinkAddress_data01_data99()

Dim msg As Object
Dim oDoc As Object
Dim H As Object

Dim newLink As String

Set msg = ActiveInspector.currentItem

If msg.GetInspector.EditorType = olEditorWord Then

Set oDoc = msg.GetInspector.WordEditor

For Each H In oDoc.Hyperlinks

Debug.Print " Address: " & H.Address

If InStr(H.Address, "data01") Then
newLink = Replace(H.Address, "data01", "data99")
Debug.Print newLink
Shell "C:\WINDOWS\explorer.exe " & newLink, 1
End If

Next

End If

Set msg = Nothing
Set oDoc = Nothing
Set H = Nothing

End Sub

nmgmarques
02-01-2017, 02:12 AM
This switches the text and opens the link with Windows Explorer. You do not click on the link, just open the item.


Option Explicit

Private Sub HyperlinkAddress_data01_data99()

Dim msg As Object
Dim oDoc As Object
Dim H As Object

Dim newLink As String

Set msg = ActiveInspector.currentItem

If msg.GetInspector.EditorType = olEditorWord Then

Set oDoc = msg.GetInspector.WordEditor

For Each H In oDoc.Hyperlinks

Debug.Print " Address: " & H.Address

If InStr(H.Address, "data01") Then
newLink = Replace(H.Address, "data01", "data99")
Debug.Print newLink
Shell "C:\WINDOWS\explorer.exe " & newLink, 1
End If

Next

End If

Set msg = Nothing
Set oDoc = Nothing
Set H = Nothing

End Sub

Thanks for replying. I pasted the code into my ThisOutlookSession. I pasted it at the very top since I have som more code in there for other purposes. Unfortunately, either clicking or right clicking and selecting open does nothing for me and I get the same popup saying "We can't find '\\company.biz\data01\...' Please make sure you're using the correct location or web address." So it seems the data01 is still not getting replaced. :(

skatonni
02-01-2017, 10:31 AM
" ... do not click on the link, just open the item." then run the code.

nmgmarques
02-02-2017, 02:37 AM
" ... do not click on the link, just open the item." then run the code.
I finally got it. Open the mail, then select and run the code. I was trying to open the link. That worked! I then made it a macro and now have that resting in my toolbar. So I am a click away from opening the files when needed. Thanks a bunch!