Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-21-2023, 08:09 PM
AlanCantor AlanCantor is offline Remove hypertext from clipboard Windows 10 Remove hypertext from clipboard Office 2019
Competent Performer
Remove hypertext from clipboard
 
Join Date: Nov 2020
Posts: 137
AlanCantor is on a distinguished road
Default Remove hypertext from clipboard

I'm using a script that copies the content of a table in a Word document:



Code:
Selection.Tables(1).Range.Copy
The script has been working beautifully... until I stumbled on a problem: a subsequent step in the macro fails if a cell in the table contains hypertext (e.g., a clickable email or web address).

This problem would evaporate if I could strip away the hypertext from the selection, or from the clipboard after the text is copied.

Any thoughts on how my macro might eliminate hypertext? Example: if xxx@yyy.zzz is a clickable link in the table, I want the text of the email address, but without it being a hypertext.

I'd be good if the macro stripped away hypertext from the table before copying the table. But my preference would be for the change to happen in Variable-Land.
Reply With Quote
  #2  
Old 01-21-2023, 08:27 PM
AlanCantor AlanCantor is offline Remove hypertext from clipboard Windows 10 Remove hypertext from clipboard Office 2019
Competent Performer
Remove hypertext from clipboard
 
Join Date: Nov 2020
Posts: 137
AlanCantor is on a distinguished road
Default

I think I found a solution:


Code:
        Selection.Tables(1).Range.Fields.Unlink
        Selection.Tables(1).Range.Copy
Reply With Quote
  #3  
Old 01-22-2023, 10:41 AM
Charles Kenyon Charles Kenyon is offline Remove hypertext from clipboard Windows 11 Remove hypertext from clipboard Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

That will work except:
  1. Now the fields in the original are also unlinked, and
  2. There may be fields like calculation fields that you want to keep active.
If those are not problems, fine. If these are problems, let us know. Essentially what you would want is to unlink any hyperlink fields in the pasted text rather than original table.
Reply With Quote
  #4  
Old 01-22-2023, 11:49 AM
AlanCantor AlanCantor is offline Remove hypertext from clipboard Windows 10 Remove hypertext from clipboard Office 2019
Competent Performer
Remove hypertext from clipboard
 
Join Date: Nov 2020
Posts: 137
AlanCantor is on a distinguished road
Default

Hi Charles,

I would prefer to retain hypertext links in the table. Once the table is in the clipboard, that would be the perfect moment to eliminate hypertext.


But if stripping hypertext from the clipboard is too complicated, I can live with my solution!
Reply With Quote
  #5  
Old 01-22-2023, 07:09 PM
Charles Kenyon Charles Kenyon is offline Remove hypertext from clipboard Windows 11 Remove hypertext from clipboard Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I would not attempt stripping it from the clipboard, but from the pasted text. If necessary, you could create a scratch document, paste it there, and clear it from the pasted text, then copy that and close the scratch document without saving, then you would have it in the clipboard.

Here is a macro that unlinks all hyperlinks in the first table of a document.

Code:
Sub HyperlinkFieldUnlink()
    '   Charles Kenyon 2023-01-22
    Dim oField As Field
    Dim oRange As range
    On Error Resume Next
    Set oRange = ActiveDocument.Tables(1).range
    For Each oField In oRange.Fields
        If oField.Type = wdFieldHyperlink Then
            oField.Unlink
        End If
    Next oField
    Set oField = Nothing
    On Error GoTo -1
    Set oRange = Nothing
End Sub
Reply With Quote
  #6  
Old 01-22-2023, 08:25 PM
AlanCantor AlanCantor is offline Remove hypertext from clipboard Windows 10 Remove hypertext from clipboard Office 2019
Competent Performer
Remove hypertext from clipboard
 
Join Date: Nov 2020
Posts: 137
AlanCantor is on a distinguished road
Default

Hi Charles,


This works nicely, too. I was able to modify your code so the table, sans hypertext, is copied to the clipboard. Thank you!


The reason I want to strip hypertext from the clipboard, rather than from the table, is that the text, after it's copied, doesn't get pasted. I assign whatever is in the clipboard to a text variable, and parse it. But I know nothing about the metadata associated with the hypertext, so I can't delete it. I was hoping there might be a way to unlink hypertext from the clipboard before I assign the clipboard to a variable.
Reply With Quote
  #7  
Old 01-23-2023, 11:09 AM
Charles Kenyon Charles Kenyon is offline Remove hypertext from clipboard Windows 11 Remove hypertext from clipboard Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by AlanCantor View Post
Hi Charles,


This works nicely, too. I was able to modify your code so the table, sans hypertext, is copied to the clipboard. Thank you!


The reason I want to strip hypertext from the clipboard, rather than from the table, is that the text, after it's copied, doesn't get pasted. I assign whatever is in the clipboard to a text variable, and parse it. But I know nothing about the metadata associated with the hypertext, so I can't delete it. I was hoping there might be a way to unlink hypertext from the clipboard before I assign the clipboard to a variable.
There may well be a way. However, I do not know it and suggested a workaround.
  1. After copying, create a new blank document.
  2. Paste into that document.
  3. Run the macro to strip out the hyperlinks.
  4. Copy the modified text from the new document.
  5. Close the new document without saving.
At this point, the clipboard contains the text without the hyperlinks.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing hypertext to normal text tcritchley07 Word 2 11-23-2019 09:52 AM
Error with Clipboard - Getting Spaces Out of Clipboard StephenRay Word VBA 14 09-27-2017 01:07 PM
Remove hypertext from clipboard Hypertext links within document? (not to a website) cosiyak Word 1 05-22-2011 01:26 PM
Remove hypertext from clipboard Hypertext Question Juc1 Word 6 05-05-2011 06:09 AM
Remove hypertext from clipboard hypertext link to a specific page of a pdf file serbring OneNote 6 03-04-2011 01:20 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:06 PM.


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