Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2020, 09:56 AM
alex100 alex100 is offline Finding the position of a keyword in a seamless way Windows 7 64bit Finding the position of a keyword in a seamless way Office 2016
Advanced Beginner
Finding the position of a keyword in a seamless way
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Finding the position of a keyword in a seamless way

I am using the routine below to find the position of a keyword inside a document.



The problem is that the code will also select the matching text, and reposition the page so that this will be displayed at the top of the Word application.

How can I get the position of the keyword in a seamless way, without having it selected and the page repositioned, please?

Code:
With Selection.Find
    .ClearFormatting
    .Text = "keyword"
    .Font.Size = 10
    .Font.Name = Verdana
    .Forward = True
    .Wrap = wdFindStop
    .Execute
    If .Found = True Then
        Position = Selection.Start
    End If
End With
MsgBox (Position)
Alex
Reply With Quote
  #2  
Old 10-26-2020, 03:05 PM
Guessed's Avatar
Guessed Guessed is offline Finding the position of a keyword in a seamless way Windows 10 Finding the position of a keyword in a seamless way Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

If you don't want to change the selection, you use Ranges instead
Code:
Sub aTest()
  Dim aRng As Range
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .Text = "keyword"
    .Font.Size = 10
    .Font.Name = "Verdana"
    .Forward = True
    .Wrap = wdFindStop
    .Execute
    If .Found = True Then
      MsgBox "Found at: " & aRng.Start
    Else
      MsgBox "Not found"
    End If
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-27-2020, 01:03 AM
alex100 alex100 is offline Finding the position of a keyword in a seamless way Windows 7 64bit Finding the position of a keyword in a seamless way Office 2016
Advanced Beginner
Finding the position of a keyword in a seamless way
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Works great, thank you very much!

Alex
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding raised characters by 0.5 pt step (Font.Position pb) iwonder Word VBA 1 07-14-2017 07:57 AM
Finding the position of a keyword in a seamless way Only display rows containing a keyword? King Mustard Excel 2 04-07-2017 12:06 AM
Textboxes position isn't equal to initial position dxdevil Word VBA 0 01-30-2017 04:32 AM
Finding the position of a keyword in a seamless way Finding the graphics and inserting the keyword Ajay2506 Word VBA 4 06-28-2016 05:34 AM
Finding the position of a keyword in a seamless way Multiple keyword search in WORD tvincent8118 Word VBA 1 06-23-2015 04:45 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:37 PM.


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