Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-22-2024, 08:55 AM
IndianaITGuy IndianaITGuy is offline How to determine the end of a block of text Windows 11 How to determine the end of a block of text Office 2019
Novice
How to determine the end of a block of text
 
Join Date: Mar 2024
Location: Martinsville, IN
Posts: 25
IndianaITGuy is on a distinguished road
Default How to determine the end of a block of text

I am working with blocks of text in a Word Document that start with



;PATH:2 - 5AX TRIM
;VIEW:9 - ORIENT - ANGLES: 0,90
;TOOL:3 - DIAM:.25 CRAD:0 REF GL:0
;DESC: 0.2500 DIA - 2 FLUTE - ENDMILL
;MATL: HSS
M06 T3.3
(UIO,Z(-1*L370))
(TCP,5)
X-2.1181 Y-1.3104 A0. C283.627 S18000 M03
A22.314 C233.775
Z1.749
G01 Z.749 F50.

Then has multiple lines of some permutation of:

X-1.8601 Y-1.5577 Z-.1887 A22.244 C233.883


Then ends with
<Random Text> F50.
G00 Z4.


There are multiple blocks of text in this format. I want to do DO-WHILE for each iteration of blocks in this format. I'm not sure how to set the DO-WHILE parameters to take advantage of these consistent markers before and/or after these blocks of text.

Can anyone help?
Reply With Quote
  #2  
Old 03-22-2024, 09:24 AM
gmaxey gmaxey is offline How to determine the end of a block of text Windows 10 How to determine the end of a block of text Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "PATH:2 - 5AX TRIM*\<*\>*G00 Z4"
    .MatchWildcards = True
    Do While .Execute
      oRng.Select
      'or do what you wish with the range of text
    Loop
  End With
lbl_Exit:
  Exit Sub
  
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 03-27-2024, 07:02 AM
IndianaITGuy IndianaITGuy is offline How to determine the end of a block of text Windows 11 How to determine the end of a block of text Office 2019
Novice
How to determine the end of a block of text
 
Join Date: Mar 2024
Location: Martinsville, IN
Posts: 25
IndianaITGuy is on a distinguished road
Default

I don't understand why you use .Execute instead of .Find.Found. Why do you expect .Execute to mirror whatever .Find.Found ends up being? Intuitively it seems to me .Execute is a flag indicating whether or not the Find operation was done, and .Find.Found indicates whether the desired pattern was found. The Find operation could have been Executed without anything being Found. Then it seems their values should not match.
Reply With Quote
  #4  
Old 03-27-2024, 07:11 AM
Italophile Italophile is offline How to determine the end of a block of text Windows 11 How to determine the end of a block of text Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Find.Executes returns True if a match is found. It is more reliable than Found and requires less code.
Reply With Quote
  #5  
Old 03-27-2024, 08:49 AM
gmaxey gmaxey is offline How to determine the end of a block of text Windows 10 How to determine the end of a block of text Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Demo below is Microsoft example of the "Found" property. DemoII below is my code which to me proves that "Found" is utterly useless:


Code:
Sub Demo()
  With Selection.Find
   .ClearFormatting
   .Font.Bold = True
   .Execute FindText:="Hello", Format:=True, Forward:=True
   If .Found = True Then
    .Parent.Expand Unit:=wdParagraph
    .Parent.Copy
   End If
End With
End Sub
Sub DemoII()
  With Selection.Find
    .ClearFormatting
    .Font.Bold = True
    If .Execute(FindText:="Hello", Format:=True, Forward:=True) Then
      .Parent.Expand Unit:=wdParagraph
      .Parent.Copy
    End If
  End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 04-01-2024, 10:29 AM
TessaMurillo TessaMurillo is offline How to determine the end of a block of text Windows Vista How to determine the end of a block of text Office 2010
Advanced Beginner
 
Join Date: Mar 2024
Posts: 33
TessaMurillo has a little shameless behaviour in the past
Default

To process blocks of text in a Word document using a DO-WHILE loop, you can use various techniques to determine the start and end of each block. In your case, since the blocks start with ";P ATH:2 - 5AX TRIM" and end with "<Random text> F50. G00 Z4.", you can use these lines as the start and end conditions for the loop.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Building Block Text into a variable tonse Word VBA 1 11-16-2023 06:10 AM
how to create a block text and when click on the title of block hide and unhide the block labasritas@free.fr Word 4 09-17-2017 01:17 PM
What is this block of text? nyempire Word 5 05-26-2016 06:08 AM
how to make building block content control determine bb to display elsewhere jamles12 Word VBA 5 11-16-2013 11:38 AM
Anyway to determine time/date of text creation? pureride Word 1 01-05-2010 02:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:32 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