473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

How to Suppress UNC Replacement in Hyperlink Objects

Oralloy
988 Expert 512MB
Folks,

We have an interesting problem here in Excel 2007. I don't know if this problem appears in any other versions, or not.

Essentially I'm using VBA code to update hyperlinks, replacing the \\system-name\share-name with an abstract drive letter. Unfortunately, microsoft is translating the URL and converting the drive letter back into the \\system-name\share-name form.

Do any of you know how I can suppress this automatic replacement?

Here is an abstracted version of the code:
Expand|Select|Wrap|Line Numbers
  1. Sub Hyperlinks_Find_Replace()
  2. ''
  3. ''  Macro to find/replace update the hyperlink targets in
  4. ''  the active workbook.
  5. ''
  6.   ''--string to replace
  7.   Dim sOld As Variant
  8.   sOld = "\\server\ShareName"
  9.  
  10.   ''--replacement value
  11.   Dim sNew As Variant
  12.   sNew = "P:"
  13.  
  14.   ''--which workbook?
  15.   Dim book As Excel.Workbook
  16.   Set book = Excel.ActiveWorkbook
  17.  
  18.   ''--work off each sheet
  19.   Dim sheet As Excel.Worksheet
  20.   For Each sheet In book.Worksheets
  21.  
  22.     Dim hLink As Excel.Hyperlink
  23.     Dim vOld As String
  24.     Dim vNew As String
  25.  
  26.     For Each hLink In sheet.Hyperlinks
  27.       vOld = hLink.Address
  28.       vNew = VBA.Replace(vOld, sOld, sNew)
  29.  
  30.       If vOld <> vNew Then
  31.         hLink.Address = vNew
  32.       End If
  33.     Next hLink
  34.  
  35.   Next sheet
  36.  
  37. End Sub
  38.  
And yes, I have verified in the debugger that the update is being done, and that it is ineffectual.

I can use the same loop and replace the share name with no difficulty.

Thank You,
Oralloy
Aug 15 '11 #1

✓ answered by NeoPa

I know you've been having difficulties posting recently so I'll update that we chatted together and tested and came to the conclusion that, as far as we were able to tell at least, this behaviour on the part of Excel with regard to hyperlinks to network drives is simply how it works. It's not optional. It just changes it automatically back to the UNC notation whenever it finds any reference in the .Address to a networked drive.

An option may be to set up a machine where the P: drive is not networked but reflects the same structure as your networked drive (at least as far as all the hyperlinked items go - You can use the DOS command SUBST to do this.), run the code (to change all the addresses to the P: format) within this setup then save it. This version should work when opened anywhere else.

2 2434
NeoPa
32,556 Expert Mod 16PB
Before I go any further, can I assume when you refer to URLs in your question you're really meaning UNCs?

Regardless of the answer, you have my full attention. You answered a number of my threads in SQL a while back so you have plenty credit :-)

While you're posting, can you explain where the offending automatic change is happening (A line # would be good).
Aug 15 '11 #2
NeoPa
32,556 Expert Mod 16PB
I know you've been having difficulties posting recently so I'll update that we chatted together and tested and came to the conclusion that, as far as we were able to tell at least, this behaviour on the part of Excel with regard to hyperlinks to network drives is simply how it works. It's not optional. It just changes it automatically back to the UNC notation whenever it finds any reference in the .Address to a networked drive.

An option may be to set up a machine where the P: drive is not networked but reflects the same structure as your networked drive (at least as far as all the hyperlinked items go - You can use the DOS command SUBST to do this.), run the code (to change all the addresses to the P: format) within this setup then save it. This version should work when opened anywhere else.
Aug 16 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

53
by: Kerberos | last post by:
I followed Dan Cederholm's image replacement tutorial, to replace a header tag by a logo. The h1 is clickable if no CSS is applied but it I replace it by the logo, the area isn't clickable anymore...
1
by: herbert | last post by:
I need to use XML file as a replacement for a script file. The XML file is is created by a (graphical) editor and the XML file then drives a runtime engine as in WorkFlow or VoiceMail systems ...
6
by: dog | last post by:
Does anyone know how to use a hyperlink in MS Access (I'm using 97) to open a report or form within the same database? I have a form in my database, I have put a label on it, some text, and when...
0
by: MJBAccess | last post by:
I'm trying to use a command button to print a Word document that is in a Hyperlink field. I keep getting Run-Time Error 5273 and it says the document name or path is not valid. The Hyperlink...
20
by: Paul D. Boyle | last post by:
Hi all, There was a recent thread in this group which talked about the shortcomings of fgets(). I decided to try my hand at writing a replacement for fgets() using fgetc() and realloc() to read...
3
by: wazoo | last post by:
I'm hoping someone here might help me with this. I'm putting the finishing touches on my intranet web app, and I'm adding some simple JavaScript to my VB.Net Webforms. This works:...
15
by: Jeff | last post by:
Hey gang. i have this Response.Write Replace(Rs("Event_Details") & " ", vbCrLf, "<BR>") & vbCrLf coming from access db. how can i get that to make a hyperlink clickable as well??
0
by: pravi | last post by:
I am using a webbrowser control in my C# application. I would like to know if there is any way to capture the URL of the hyperlink that I click. I need to suppress the default navigation of the...
1
by: Jonas Pedersen | last post by:
hi, I am looking into reusing code to limit number of pages. When ever I display a user's name on the site, It is with a hyperlink so you can view the user profile in a popup window. Is there a...
0
by: PopeDarren | last post by:
_Short version_: Is it possible to directly access the hyperlink objects in the MenuItem and TreeNode objects on the server-side? If so, how do I do it? _Long version_: I'm getting to the end...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.