Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2016, 10:55 AM
curlgary curlgary is offline Macro to go to text Windows 7 64bit Macro to go to text Office 2013
Novice
Macro to go to text
 
Join Date: Jan 2016
Location: Birmingham, AL
Posts: 2
curlgary is on a distinguished road
Default Macro to go to text

Need a macro to operate from a button to jump to a text string within a word doc. Attached is a simplified version of what I am trying to do. I need the buttons to have code behind them to jump to a line in the document. For instance when you click the LiDAR Capture button it jumps to the point in the document with the first instance of "Initial LiDAR Capture". The Initial Work button needs to jump to the first instance in the document of "Initial Work". This is a simplified example as my real doc has many pages. I need the VBA code to go behind the button, so I can assign that macro to the button.
Attached Files
File Type: docx Go To Text String.docx (15.2 KB, 11 views)
Reply With Quote
  #2  
Old 01-05-2016, 06:29 PM
macropod's Avatar
macropod macropod is offline Macro to go to text Windows 7 64bit Macro to go to text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use code like in the document's 'ThisDocument' code module:
Code:
Private Sub CommandButton1_Click()
Call GotoText("Initial LiDAR Capture")
End Sub
 
Private Sub CommandButton3_Click()
Call GotoText("Initial Work")
End Sub
 
Sub GotoText(StrTxt As String)
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = StrTxt
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = True
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  If .Find.Found = True Then .Select
End With
Application.ScreenUpdating = True
End Sub
Note that your document will have to be saved in the docm format for this to work once it's been closed & re-opened; otherwise you'll lose the code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-07-2016, 06:42 AM
curlgary curlgary is offline Macro to go to text Windows 7 64bit Macro to go to text Office 2013
Novice
Macro to go to text
 
Join Date: Jan 2016
Location: Birmingham, AL
Posts: 2
curlgary is on a distinguished road
Default

Paul,
This worked perfectly.
Thanks for your help.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to go to text I need to convert shaded text into highlighted text on about 80 different long documents. VBA macro? AustinBrister Word VBA 8 05-28-2015 02:42 PM
Macro to add title in header is missing text once macro is run shawnee24 Excel Programming 1 05-27-2015 11:50 PM
Macro to add title in header is missing text once macro is run shawnee24 Word VBA 3 05-27-2015 12:35 PM
Microsoft Word macro to find text, select all text between brackets, and delete helal1990 Word VBA 4 02-05-2015 03:52 PM
Macro to find coloured text and replace with form-field/formtext containing that text tarktran Word VBA 1 11-26-2014 08:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft