Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Word Object code
#5
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
Code:
Copy      Help
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)
JaconWord.new
Code:
Copy      Help
function Word.Application'app $name

jaw_path=_s.expandpath(name)

Word.Documents docs=app.Documents
jaw_doc=docs.Add
jaw_rng=jaw_doc.Range
JaconWord.find
Code:
Copy      Help
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
JaconWord.font
Code:
Copy      Help
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
JaconWord.appendtext
Code:
Copy      Help
function str&text [$fname] [size] [style]

if len(fname)
,font(fname size style)

jaw_rng.Text=text
jaw_rng.Start=jaw_rng.End
JaconWord.insertpicture
Code:
Copy      Help
function $path

jaw_doc.Application.Selection.InlineShapes.AddPicture(path)
err
jaw_rng.Select()


Attached Files
.qml   AutoWord.qml (Size: 2.06 KB / Downloads: 332)


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)