Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use QM's regular expression to replace text in word
#15
kyjdp Wrote:I tried QM to find the replacement function, success, QM too powerful, than Word vba lookup replacement function, much more powerful :lol:

Macro Macro2
Code:
Copy      Help
;/exe 1
out

typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._getactive ;;connect to Word. Note: need the /exe 1.
Word.Document doc=app.ActiveDocument
str s=doc.Content.Text
;out s
s.findreplace("[13]" "[10]") ;;Word text newlines are [13]
str rx=
;(?xm)
;help
ARRAY(POINT) a; int i
if(!findrx(s rx 0 4 a)) end "failed, regular expression"
for i 0 a.len
,VARIANT v1(a[0 i].x) v2(a[0 i].y)
,Word.Range ran=doc.Range(v1 v2)
,ran.Bold=1
,ran.Font.Size=15

;BEGIN PROJECT
;main_function  Macro2
;exe_file  $my qm$\Macro2.qmm
;flags  6
;guid  {B5CA9DC3-252F-4349-AB94-A08505C19716}
;END PROJECT

______________________________________________
Replace the text of the code

Macro Macro2
Code:
Copy      Help
;/exe 1
out

typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._getactive ;;connect to Word. Note: need the /exe 1.
Word.Document doc=app.ActiveDocument
str s=doc.Content.Text
;out s
s.findreplace("[13]" "[10]") ;;Word text newlines are [13]
str rx=
;(?xm)
;help
ARRAY(POINT) a; int i
if(!findrx(s rx 0 4 a)) end "failed, regular expression"
for i 0 a.len
,VARIANT v1(a[0 i].x) v2(a[0 i].y)
,Word.Range ran=doc.Range(v1 v2)
,ran.Text="HELP"

Use the pointer to replace, when the replacement character is very long is unsuccessful, :oops:


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)