Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-04-2022, 01:14 PM
Testeris Testeris is offline Make hyperlink in macro using Clipboard Windows 10 Make hyperlink in macro using Clipboard Office 2016
Novice
Make hyperlink in macro using Clipboard
 
Join Date: Nov 2022
Posts: 8
Testeris is on a distinguished road
Default Make hyperlink in macro using Clipboard

Hi all,
I am trying to create a word file to use with another macro. I need to select some text and make it hyperlink that I copy/cut from a line below (it is automatically generated in Excel and linked/updated at the time of opening the doc). The result is cut and saved into separate Word files, as part of a big batch file.



So far I scroll, select and cut the hyperlink text I need. Then I go back several numbers to select the reference and run a subroutine to paste in the hyperlink text onto my selection.


What I encounter is error "DataObject:getfromclipboard openclipboard failed". I debug, yellow arrow at "MyData.GetFromClipboard" and when clicked the green arrow (F5) it goes through as expected.



I can't get it done in one go. What I am doing wrong?

Sorry, I am "copypaster" only. My suspicion is that CUT does not put into Clipboard, so I tried to COPY and then cut, and both...

P.S. An example of the text in Bulgarian (I am not)




... several lines...
Текстовете, приети на 4 май 2022 г. относно освобождаването от отговорност във връзка с изпълнението на Бюджет 2020 г., са публикувани в [Here goes the hyperlink]-->ОВ L 258, 5.10.2022.
https://eur-lex.europa.eu/legal-content/BG/TXT/?uri=OJ%3AL%3A2022%3A258%3AFULL
... several lines...


My "macro":
Sub aMacro1()
'
' aMacro1 Macro
'
Dim MyData As DataObject
Dim strAddr As String
Dim strTitle As String
Set MyData = New DataObject

Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdParagraph, Count:=9
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
' cut the link text
' Selection.Copy
Selection.Cut
MyData.GetFromClipboard
strAddr = MyData.GetText

' selecting the location where to overlay
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveLeft Unit:=wdWord, Count:=10, Extend:=wdExtend
' sub to put in the hyperlink -->
' Commented FOR REUSING IF IT FAILS
' Dim MyData As DataObject
' Dim strAddr As String
' Dim strTitle As String

' On Error Resume Next - skipped the error but did not do the job

' MyData.GetFromClipboard
' strAddr = MyData.GetText

' Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
' Selection.Copy
' MyData.GetFromClipboard

ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=strAddr, SubAddress:="", ScreenTip:="", TextToDisplay:=Selection.Range

' End of the insert

' return to the beginning of the page and/or continue to other macto
Selection.HomeKey Unit:=wdStory
End Sub


Thanks
Reply With Quote
 

Tags
getfromclipboard, hyperlink, macro error



Similar Threads
Thread Thread Starter Forum Replies Last Post
Make hyperlink in macro using Clipboard Copy Specific Text String To Clipboard At End Of Macro et_33 Excel Programming 8 10-11-2022 06:24 AM
WORD MACRO COPY/PAST from clipboard rachidlea Word VBA 0 11-16-2021 09:38 AM
Macro for copying in clipboard more than one selected text ghostwhisperer86 Outlook 0 03-31-2019 07:47 AM
Make hyperlink in macro using Clipboard How to extract selected hyperlink address to clipboard? poetofpiano Word VBA 8 02-18-2018 07:17 PM
Add Hyperlink in Visio that when clicked copies something to your clipboard MoHyB Visio 0 11-10-2017 08:55 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:54 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