View Single Post
 
Old 11-07-2022, 07:36 AM
Testeris Testeris is offline Windows 10 Office 2016
Novice
 
Join Date: Nov 2022
Posts: 8
Testeris is on a distinguished road
Default

Thank you, GMayor for your time.

I feel very uncomfortable, but it still doesn't perform exactly as needed. This is what we have accomplished so far. I added "text to display" to the code. The selection where to post will be different for each language.

Imgur: The magic of the Internet

In short, it still needs to replace the selected text with the hyperlinked text (see 2nd example what it does now)

Code:
Sub aOverlayHTMLDecharges()
  '
  ' aOverlayHTMLDecharges Macro
  '
      Dim MyData As DataObject
      Dim strAddr As String
      Dim strTitle As String
      Set MyData = New DataObject
   
      Dim oRng As Range
      Dim sLink As String
  ' Selecting the HTML line - CHR13 - COMMENTED OUT
      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
   
  ' GMAYOR code - selecting URL
      Selection.HomeKey
      Set oRng = Selection.Paragraphs(1).Range
      oRng.End = oRng.End - 1
      sLink = oRng.Text
   
      'remove the original hyperlink
      oRng.Text = ""
   
  '    clipboard.SetText Selection.Hyperlinks(1).Address
  '    clipboard.PutInClipboard
          
  '    MyData.GetFromClipboard  '<-- not sure where in the code to put it
  '    strAddr = MyData.GetText
      
  ' selecting the location where to overlay - TO MODIFY FOR EACH LANGUAGE

      Selection.MoveLeft Unit:=wdCharacter, Count:=2   '
      Selection.MoveLeft Unit:=wdWord, Count:=9, Extend:=wdExtend '
   
  'TESTING
      'set the range to the new location
  '    oRng.MoveStartUntil "-", wdBackward
  '    oRng.Start = oRng.Start - 21
      'collapse the range to its start
  '    oRng.Collapse 1
   
  ' sub to put in the hyperlink   -->
      MyData.GetFromClipboard
      strAddr = MyData.GetText
   
  '  What to do with these? Which one on the new selection?
  '    oRng.Hyperlinks.Add oRng, sLink
   
      oRng.Hyperlinks.Add oRng, sLink, SubAddress:="", ScreenTip:="", TextToDisplay:=Selection.Range
  '    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=strAddr, SubAddress:="", ScreenTip:="", TextToDisplay:=Selection.Range
   
  ' End of the insert
   
  Set oRng = Nothing
   
  ' return to the beginning of the page and/or continue to other macro
      Selection.HomeKey Unit:=wdStory
  End Sub
Reply With Quote