08-29-2010, 05:09 PM
Thanks Gintaras,
I just needed a little push in the right direction.
Whith a great help from MSDN library, i have created this:
Macro AutoWord
JaconWord.new
JaconWord.find
JaconWord.font
JaconWord.appendtext
JaconWord.insertpicture
I just needed a little push in the right direction.
Whith a great help from MSDN library, i have created this:
Macro AutoWord
typelib Word {00020905-0000-0000-C000-000000000046} 8.0 0x409
class JaconWord VARIANT'jaw_path Word.Document'jaw_doc Word.Range'jaw_rng Word.Range'jaw_f_rng Word.Selection'jaw_sel
def JAW_REPLACE 0x8000
Word.Application app._create
JaconWord jw.new(app "$desktop$\test.doc")
str s1="This is a Word test 123456789[]{Image1}[][]"
str s2="One Two Three Four Five[][]"
str s3="Replace text:[]{Text1}[][]End of document.[]"
str s4="abcdefghijklmnopqrstuvwxyz"
jw.font("Arial" 24 1)
jw.appendtext(s1)
jw.appendtext(s2 "Arial" 24 2)
if jw.find("{Image1}")
,jw.insertpicture("C:\Qu\bmp\Jbem0.bmp")
jw.appendtext(s3 "Arial" 14)
app.Visible = TRUE
wait 2
if jw.find("{Text1}" s4 JAW_REPLACE)
,out "Text replaced"
jw.jaw_doc.SaveAs(jw.jaw_path)
function Word.Application'app $name
jaw_path=_s.expandpath(name)
Word.Documents docs=app.Documents
jaw_doc=docs.Add
jaw_rng=jaw_doc.Range
function# VARIANT'ftxt [VARIANT'rtxt] [flags]
jaw_f_rng=jaw_doc.Range
jaw_f_rng.Find.ClearFormatting()
if jaw_f_rng.Find.Execute(ftxt)
,jaw_f_rng.Select
,if flags&JAW_REPLACE
,,jaw_f_rng.Text=rtxt
,,jaw_rng.Select()
,ret 1
ret
function $fname [size] [style] ;;style: 1 bold, 2 italic, 4 underline, 8 strikeout
jaw_rng.Text=0
if(style)
,jaw_rng.Font.Reset
,if(style&1) jaw_rng.Font.Bold=1
,if(style&2) jaw_rng.Font.Italic=1
,if(style&4) jaw_rng.Font.Underline=1
,if(style&8) jaw_rng.Font.StrikeThrough=1
if(size)
,jaw_rng.Font.Size=size
jaw_rng.Font.Name=fname
function str&text [$fname] [size] [style]
if len(fname)
,font(fname size style)
jaw_rng.Text=text
jaw_rng.Start=jaw_rng.End