PDA

View Full Version : Adding an action button that takes the user to first page



dm28949
04-17-2015, 06:54 AM
What changes do I make to this code so that it takes me to first page when the button is clicked. The document I am working on is really long and I need to have a "TOP" button in every single page. Any help will be much appreciated.



Sub Test()

'Add a command button to a new document
Dim doc As Word.Document
Dim shp As Word.InlineShape
Set doc = Documents.Add

Set shp = doc.Content.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
shp.OLEFormat.Object.Caption = "TOP"

'Add a procedure for the click event of the inlineshape
'**Note: The click event resides in the This Document module
Dim sCode As String
sCode = "Private Sub " & shp.OLEFormat.Object.Name & "_Click()" & vbCrLf & _
" MsgBox ""You Clicked the CommandButton""" & vbCrLf & _
"End Sub"
doc.VBProject.VBComponents("ThisDocument").CodeModule.AddFromString sCode

End Sub

gmayor
04-17-2015, 07:14 AM
What's wrong with using CTRL+Home? This will take you to the start of the document.

dm28949
04-17-2015, 07:21 AM
@gmayor The users are going to view this document in their phone. Also, I am trying to save the whole thing as a pdf. Is there any easy way to have this kind of link work even when it is converted to pdf?