Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Word Object code
#1
I would like to create a Word document, and inserte text from macro.
Creating and saving is no problem, but then i'm in trouble.
I have studied MSDN library about Ranges and Selections, but cannot make it work in QM.
Please help a little.
Thanks!
#2
Quote:Creating and saving is no problem

Do you have code for it? Please post here.
#3
This is my code until now..
Code:
Copy      Help
typelib Word {00020905-0000-0000-C000-000000000046} 8.0 0x409

Word.Application app._create
app.Visible = TRUE
Word.Documents docs=app.Documents

VARIANT d=_s.expandpath("$desktop$\test.doc")


Word.Document doc=docs.Add

;;;-------------------------------
Word.Range rng

rng.Start=0
;;;-------------------------------


doc.SaveAs(d)


;exit
;app.Quit
#4
In most cases you can find Word/Excel functions in popup lists, and don't need to read help.

For example, I type "doc." and look for something that could be what I need. Found "Content". Double click. Look in status bar what it returns. It is Range object. If it is an object, I can type "." again and look in the list. Found "Text" property.

Macro Macro1449
Code:
Copy      Help
;;;-------------------------------

doc.Content.Text="text"

;;;-------------------------------

or

Macro Macro1449
Code:
Copy      Help
Word.Range rng=doc.Content
rng.Text="text"
#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: 318)


Forum Jump:


Users browsing this thread: 1 Guest(s)