View Single Post
 
Old 11-29-2018, 04:12 PM
cheech1981 cheech1981 is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Nov 2011
Location: New Jersey, USA
Posts: 77
cheech1981 is on a distinguished road
Default

Hi Paul,

Actually I am not recording the copying because the copied text comes from outside the Word program (info from web). So I should have worded that question slightly differently.

Here is a video to show what I'm trying to do and the problem I am running into:
https://youtu.be/Dx88UOHFsH8

How would I go about tweaking the vba to "paste from clipboard" both at the beginning of the macro (into the Word doc) and then at the end (to create a hyperlink address)?

I am also posting the recorded vba below that I created when recording the video.

Code:
Sub Macro133()
'
' Macro133 Macro
'
'
    Selection.Paste
    Selection.HomeKey Unit:=wdLine
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "https://doi.org/"
        .Replacement.Text = "doi:"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.TypeText Text:="doi:"
    Selection.MoveLeft Unit:=wdCharacter, Count:=4
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
        "https://doi.org/10.1177%2F1077800407301175", SubAddress:="", ScreenTip:= _
        "", TextToDisplay:="doi:10.1177%2F1077800407301175"
End Sub
So it looks like I need to change the "address" field to be the string that the user currently has copied to the clipboard.
Reply With Quote