#1
|
|||
|
|||
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.
|
#2
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Paul,
This worked perfectly. Thanks for your help. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |