Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2024, 08:11 AM
IndianaITGuy IndianaITGuy is offline Puzzling Behavior Windows 11 Puzzling Behavior Office 2019
Novice
Puzzling Behavior
 
Join Date: Mar 2024
Location: Martinsville, IN
Posts: 25
IndianaITGuy is on a distinguished road
Default

OK here we go. The updates did not improve things.

Here is a shortened but relevant snippet of what I am working with.

;FILENAME:
;SCPRT :
;RUNDATE :
;POSTNAME:
;POSTREV :

G17
G40
G70
G80
G90
G500 T20 F32
FCT=0.005
G00 G79 Z(@ZPARKP1)
G00 G79 A0. C0.
;--- BEGIN TOOL LIST ---
;T 1 - Q008
;T 3 - 0.2500 DIA - 2 FLUTE - ENDMILL
;--- ENDOF TOOL LIST ---
;PATH:1 - 5AX TRIM
;VIEW:9 - ORIENT - ANGLES: 0,90
;TOOL:1 - DIAM:.5 CRAD:0 REF GL:0
;DESC: Q008
;MATL: HSS
M06 T1.1
(UAO,1)
(UIO,Z(-1*L370))
(TCP,5)
S18000 M03
G00 X12.7226 Y-7.0348 Z4. A0. C0.
A-56.441 C-76.373
Z-5.6689
G01 Z-6.6689 F50.
X2.5074 Y-.0286 Z-.8416 A-22.097 C-17.003
X2.2894 Y.0125 Z-.7499 A-21.388 C-15.526
X2.0727 Y.0485 Z-.6656 A-20.705 C-13.983
X2.045 Y.0528 Z-.6553 A-20.62 C-13.78
X1.8306 Y.0835 Z-.5797 A-19.97 C-12.165
X1.6188 Y.1099 Z-.5121 A-19.349 C-10.488
X1.4098 Y.1324 Z-.4526 A-18.759 C-8.747
X1.31 Y.142 Z-.4268 A-18.485 C-7.884
X1.1016 Y.1595 Z-.3784 A-17.93 C-6.017
X.8934 Y.1737 Z-.3376 A-17.399 C-4.056
X.6863 Y.1847 Z-.3043 A-16.894 C-2.004
X.481 Y.1924 Z-.2786 A-16.418 C0.
X.2782 Y.1969 Z-.2604 A-15.973 C2.354
X.2667 Y.197 Z-.2596 A-15.948 C2.484
X.0642 Y.1982 Z-.2492 A-15.53 C4.819
X-.1375 Y.1959 Z-.2462 A-15.14 C7.259
X-.2483 Y.1932 Z-.2475 A-14.938 C8.648
X-.2674 Y.1926 Z-.2482 A-14.953 C8.99
X-.4679 Y.1841 Z-.259 A-15.145 C12.53
X-.6704 Y.1719 Z-.2771 A-15.395 C16.017
X-.7994 Y.1623 Z-.2923 A-15.582 C18.188
X-1.0048 Y.1442 Z-.3225 A-15.924 C21.547
X-1.0627 Y.1385 Z-.3323 A-16.03 C22.473
X-1.2737 Y.1152 Z-.3725 A-16.452 C25.755
X-1.3232 Y.1092 Z-.383 A-16.559 C26.505
X-1.5384 Y.0808 Z-.4329 A-17.055 C29.67
X-1.7583 Y.0477 Z-.491 A-17.615 C32.744
X-1.8332 Y.0354 Z-.5123 A-17.817 C33.753
X-2.0586 Y-.0044 Z-.5813 A-18.461 C36.678
X-2.1625 Y-.0243 Z-.6153 A-18.775 C37.97
X-2.3941 Y-.0724 Z-.696 A-19.511 C40.722

1. We want (for now) to swap the positions of the X & Y values only
Example: X1.8306 Y.0835 Z-.5797 A-19.97 C-12.165
Becomes Y.0835 X1.8306 Z-.5797 A-19.97 C-12.165


2. The values are cleaned up so that every value has at least a leading zero. There is a value “5AX TRIM” that I’m changing temporarily to “BAD TRIM”
3. I’m finding my X & Y values by searching for “X*Y”
4. As long as the first X value on a line does not start with “X-“, I can do a CTRL- <Right Arrow> in the space just left of the “Y” three times and get to the beginning of the line. If the line starts out with “X-“, it takes 5 for some reason. So I want to set a variable to how many CTRL-RIGHTs I need.
5. Using VBA, I am unable to detect a “X-“ above the current cursor position. This is my problem.

p.s. I’m getting back into VBA after a long hiatus,m so I am still weak on things like ranges and how to just select to the beginning of a line so I am doing it this way.


Here's my VBA code:

Sub FindSwitchXandY()
'
' FindSwitchXandY
'
'

Call PrepDocument

Call SwitchXAndY

End Sub


Sub PrepDocument()
'
' Temporarily rename "5AX"
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "5AX TRIM"
.Replacement.Text = "BAD TRIM"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "-."
.Replacement.Text = "-0."
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "X."
.Replacement.Text = "X0."
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "Y."
.Replacement.Text = "Y0."
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


End Sub

Sub SwitchXAndY()

Dim NumWords As Integer


On Error Resume Next

' Go to the string "X*Y"
Selection.Find.ClearFormatting
With Selection.Find
.Text = "X*Y"
.Forward = True
.MatchWildcards = True


.Execute
End With

Do While Selection.Find.Found = True

'Go to the next space
With Selection.Find
.Text = " "
.Forward = True
.MatchWildcards = True
.Execute
End With
'Selection.Find.Execute


Selection.ClearFormatting

With Selection.Find
.Text = "X-"
.Forward = False
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

If Selection.Find.Found = True Then NumWords = 5 Else NumWords = 3
Selection.MoveLeft Unit:=wdWord, Count:=NumWords, Extend:=wdExtend

'Cut it
Selection.Cut

'Go to the next space
With Selection.Find
.Text = " "
.Forward = True
.MatchWildcards = True
.Execute
End With
'Selection.Find.Execute


'Paste the previously cut string
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.TypeText Text:=" "

' Go to the string "X*Y"
Selection.Find.ClearFormatting
With Selection.Find
.Text = "X*Y"
.Forward = True
.MatchWildcards = True
.Execute

End With

Loop

End Sub



Bottom line, "Find" doesn't work as expected in my context.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Puzzling behavior by Window shape in [Walls, Shell and Structure] csdlman Visio 3 06-12-2018 03:50 AM
Puzzling Read Only Issue BertLady PowerPoint 0 10-15-2014 11:40 AM
Odd cursor behavior markg2 Outlook 0 06-15-2010 08:33 AM
Bizarre behavior Mozydan Outlook 0 11-19-2007 08:59 AM
Odd Behavior from Outlook stonkers Outlook 0 03-14-2006 12:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:38 PM.


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