View Single Post
 
Old 11-07-2019, 05:54 AM
taryn taryn is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2015
Location: Gibraltar
Posts: 21
taryn is on a distinguished road
Default Copying text from a cell in the footer and pasting it into a hyperlink address

Hello

I am trying to create a macro that will run automatically when a word document is opened and will do the following:

1) Copy the six digits contained in a table located in the footer of the 1st page of the document;
2) Paste the above six digits into the address of a hyperlink also located in the table in the footer of the 1st page of the document (different cell) replacing some of the text already in the address.

I am completely new to word macros and the Record Macro button only does what I ask partly:
==================================================

Sub Macro3()
'
' Macro3 Macro
'
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.Range.Copy
ChangeFileOpenDirectory _
"C:\Users\taryn.avellano\Documents\ViewPoint.gibsq l01.VPMain"
Selection.Range.Hyperlinks(1).Range.Fields(1).Resu lt.Select
Selection.Range.Hyperlinks(1).Delete
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
"https://secure.worldpay.com/wcc/purchase?instId=1033965&cartId=20150013&amount=(+D T.EURO+)&currency=GBP&desc=WorldPay+Test&testMode= 100" _
, SubAddress:=""
Selection.Collapse Direction:=wdCollapseEnd
End Sub

==================================================

The above macro does copy the six digits (i.e. 20150013) and pastes it into the hyperlink address. However, it has the following limitations, which makes it unusable for me, as I need it to require no action on behalf of the user opening the document:

1) It only works when I run it after having highlighted the hyperlink object. I need it to run automatically when the word document is opened;
2) It always pastes the same six digits (i.e. 20150013) into the hyperlink address, instead of copying the six digits contained in the table located in the footer of the 1st page of the document, which changes with each document.

Any help would be greatly appreciated.

Kind regards.

Taryn
Reply With Quote