Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-14-2018, 06:57 PM
macropod's Avatar
macropod macropod is offline How to extract selected hyperlink address to clipboard? Windows 7 64bit How to extract selected hyperlink address to clipboard? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,512
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub CopyHyperlink()
Dim Rng As Range
Set Rng = Selection.Hyperlinks(1).Range.Fields(1).Code
With Rng
  .MoveStartUntil Chr(34), wdForward
  .Start = .Start + 1
  .Collapse wdCollapseStart
  .MoveEndUntil Chr(34), wdForward
  .Copy
End With
End Sub

__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 02-16-2018, 11:27 AM
poetofpiano poetofpiano is offline How to extract selected hyperlink address to clipboard? Windows 10 How to extract selected hyperlink address to clipboard? Office 2016
Novice
How to extract selected hyperlink address to clipboard?
 
Join Date: Sep 2015
Posts: 25
poetofpiano is on a distinguished road
Default

Thank you for your help macropod. Because your version only copied the name of the bookmark instead of the full file path, I used a simplified version of your suggestion as follows:

Code:
Sub CopyHyperlink()
Dim Rng As Range
Set Rng = Selection.Hyperlinks(1).Range.Fields(1).Code
Rng.Copy
End Sub
This copied the following to the clipboard:

Code:
HYPERLINK "file:///C:\\Users\\Username\\Dropbox\\Doc.docx" \l "Bookmark Name"
Then using string and regex functions in Autohotkey, I was able to pare down the clipboard to just the following:

Code:
C:\Users\Username\Dropbox\Doc.docx#Bookmark Name
This is exactly what I was looking for, so thank you so much!
Reply With Quote
  #3  
Old 02-16-2018, 02:07 PM
macropod's Avatar
macropod macropod is offline How to extract selected hyperlink address to clipboard? Windows 7 64bit How to extract selected hyperlink address to clipboard? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,512
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by poetofpiano View Post
your version only copied the name of the bookmark instead of the full file path
That suggests the actual hyperlink lacked the enclosing double quotes. You also hadn't mentioned wanting to get the hyperlink sub-address (i.e. the bookmark). In that case, try:
Code:
Sub CopyHyperlink()
Dim Rng As Range
With Selection.Hyperlinks(1).Range.Fields(1)
  Set Rng = .Code
  With .Code
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Format = False
      .Forward = True
      .Wrap = wdFindStop
      .MatchWildcards = False
      .Text = "\l"
      .Replacement.Text = "#"
      .Execute Replace:=wdReplaceAll
      .Text = "HYPERLINK"
      .Replacement.Text = ""
      .Execute Replace:=wdReplaceAll
      .Text = "^w"
      .Execute Replace:=wdReplaceAll
      .Text = Chr(34)
      .Execute Replace:=wdReplaceAll
    End With
  End With
End With
Rng.Copy
While InStr(Rng.Text, "HYPERLINK") = 0
  Undo
Wend
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract name and address. donlincolnmsof Word VBA 1 11-10-2017 12:59 PM
Add Hyperlink in Visio that when clicked copies something to your clipboard MoHyB Visio 0 11-10-2017 08:55 AM
How to extract selected hyperlink address to clipboard? Find & selected paras with highlighted text & copy to clipboard marceepoo Word VBA 1 09-14-2012 08:20 PM
How to extract selected boilerplate into a new doc mturner296 Word 0 03-29-2010 07:35 AM
How to extract selected hyperlink address to clipboard? Extract email address from field zssteen Excel 1 06-19-2009 02:32 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft