Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing a line in Word Automation 1

Status
Not open for further replies.

FoxEgg

Programmer
Mar 24, 2002
749
AU
OK guys...

First that which most of you know...

#1 there are a good number of recommendations for automating Word from VFP.... these can be found in the KeyWord Search and the FAQs

#2... I have looked and tried many of these... but the best (I believe) is the one which assumes that the reader is a cretin and the writer walks him (in my case) or her thru the issue...

I know that many of you have made suggestions before for others to look at this adddress.... but as I am probably the the ultimate VFP-cretin programmer.

I have to tell all of the normal humans out there... this site is fantastic.


I hope this links connects for those of you who want (are trying) to learn VFP to Word programming....

I can tell you that it assumes that you are a normal human being and it walks you through....the whole thing...

I am now a demi-God of VFP Word programming... but I need the help of the big-Gods...

Dear programming Gods..

Programmatically, how do I draw a line on this page....

I tried

.ActiveDocument.Shapes.AddLine(90#, 171#, 558#, 171#).Select

but it reports an error


John Fox
Fox Egg
World's worst VFP Programmer
Sydney Oz
 
John

You were really close this time ;-)

.ActiveDocument.Shapes.AddLine(90#, 171#, 558#, 171#).Select


ow.ActiveDocument.Shapes.AddLine(90,171,558,171) Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
John

BTW the link you posted does not get me anywhere other than page 404. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
John

.ParagraphFormat.Alignment = wdAlignParagraphCenter

I'm not sure how the above line relates to opening a document.

Code:
ow=CREATEOBJECT("word.application")
ow.Documents.Open("c:\test.doc")
ow.visible =.t.

I'm not sure want you want to do with the above line? Center the text?



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
FoxEgg

.ParagraphFormat.Alignment = wdAlignParagraphCenter

Since VFP knows nothing about Word Constants you have tell it what the constant is.

ow=CREATEOBJECT("word.application")
ow.Documents.Add
ls=ow.selection
ls.ParagraphFormat.Alignment= 1 && wdAlignParagraphCenter
ow.Visible=.t.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Thanks again...
I havent tried these yet, but will.. but I am working thru the MSWord Object browser.. copying constants to a Text file and then gonna and try create a .h (header file)

My entire code (that I copied) is on another post.... on Word Automation.... you can see I had trouble with those pesky wd prefixes....

John

 
Oh and you are right my question was shonky..sorry... clarification

Problem #1 How do I open an existing document AND
Problem #2 How do I centre a paragraph

You have answered both, thanks.

What do you think about creating the header file with the MSWord extensions contained ??

John
12MN Oz time
 
John

What do you think about creating the header file with the MSWord extensions contained ??

All of them? It's going to be quite the header file.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Your code worked brilliantly ....(AGAIN) (what we need is some new compliment cliche s)

ParagraphFormat.Alignment= 1

But, where is this documented ? (Don't worry if the answer is too obvious)

*****OTHER ISSUE*********

ow=CREATEOBJECT("word.application")
ow.Documents.Open("c:\test.doc")
ow.visible =.t.



But what if "test.doc" is no find...

how can I open (specify) a new file... eg

My patient file number is "GA851007" = GAgnon plus date of birth backwards... year, month, day (Oh! and btw Happy Birthday, Mike)..

If it exists... go to the bottom and add more detail..

If it doesnt exist,,, create new and type type and go from there...


Cheers

John


 
John

ParagraphFormat.Alignment= 1

But, where is this documented ? (Don't worry if the answer is too obvious)


I get my info with VFP7.0, either with intellinsense or the
Object browser.

But what if "test.doc" is no find...


To get an existing document.

Code:
cWordDoc = GETFILE("doc","Get word document","Use")
ow=CREATEOBJECT("word.application")
ow.Documents.Open(cWordDoc)
ow.visible =.t.




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Mike I went to the VFP Object Browser..

Opened the MS Word Object Library (version 9)

Opened Paragraphformat

Saw the Alignment Property

But where do you fine the information that suggests that its value should be = 1

(Maybe I shouldn't be trying to work out 'Why, it should work' and "Just Do It"


John

 
One of the other problems is that I cannot seem to get Intellisense to work in the program editor...

I tried typing

_VFP.EditorOptions = "LQKT" in the command window... nope!


I tried <ctrl> I and <ctrl> J .. no good!

In the program editor the Intellisense does not work. It does work in the code section of the Form designer !!!

Beats me.

John

4am

 
Mike I went to the VFP Object Browser..

John, this one I got from intellisense, type these in the command window.

ow=CREATEOBJECT(&quot;word.application&quot;)
ow.Documents.Add
ls=ow.selection
ls.ParagraphFormat.Alignment= at this intellisense should open up and list all the alignments. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
John

In the program editor the Intellisense does not work. It does work in the code section of the Form designer !!!

That is correct.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Actually, intellisense will work in a program file, you just need to &quot;help&quot; it a bit. Add this before your CreateObject()
Code:
LOCAL ow as &quot;word.application&quot;
Rick
 
Mike, That Intellisense from the command window works well.

Combining the bits of knowledge that are on this post... At this point in time with my limited knowledge... I would suggest for others wanting to &quot;Automate Word&quot;

1. Start Word
2. Record a Word macro which does what you want it to do
3. Open the Word Object Browser and look at the macro you just created and copy the code to a txt file
4. Open VFP and open its Object Browser
5. Open the Word Library in the VFP Object Browser
6. OPen the properties
7. Line by line get the &quot;conversions&quot; for the expressions such as wdParagraph and use the FIND to get the VFP equivalent...
8. then use Mike's suggestion of typing the following code into the command window... eg for Paragraphformat etc etc


ow=CREATEOBJECT(&quot;word.application&quot;)
ow.Documents.Add
ls=ow.selection
ls.ParagraphFormat.Alignment= at this intellisense should open up and list all the alignments


Use the intellisense option desired and that gives you the exact final code....

eg ls.ParagraphFormat.Alignment= 1 && wdAlignParagraphCenter

stick that into your prg file


Piece of Cake.....

*************
Now to add VFP data to the Word doc (ie to Insert fields into a word document)

stick this into the appropriate point of code

with .selection
.TypeText(ALLTRIM(customer.title)+&quot;. &quot;+ALLTRIM(customer.first_name)+&quot; &quot;+ALLTRIM(customer.last_name))

.TypeParagraph
.TypeText(ALLTRIM(customer.street))
.TypeParagraph

etc
etc

endwith



John
 
Rick, I added

LOCAL ow as &quot;word.application&quot;

in the command window ahead of the

ow=CREATEOBJECT(&quot;word.application&quot;)
ow.Documents.Add
ls=ow.selection
ls.ParagraphFormat.Alignment=1


went to the prg file editor... and still no intellisense !!!

Where am I going wrong ? It would be great to have the prg file editor with intellisense.

John
 
John

A slight variation, to get intellisense to pop-up inside a load of a form for example. Just put this:
Code:
ow=CREATEOBJECT(&quot;word.application&quot;)
ow.Documents.Add

Select the two lines (so they are blue) and right-mouse on the selection and use the &quot;execute selection&quot; and the next line type :
ow.Documents. at this point intellisense shoudl kick in. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
John

Just to add a few things to this:

with .selection
.TypeText(ALLTRIM(customer.title)+&quot;. &quot;+ALLTRIM(customer.first_name)+&quot; &quot;+ALLTRIM(customer.last_name))
.TypeParagraph
.TypeText(ALLTRIM(customer.street))
.TypeParagraph
.InlineShapes.AddPicture(&quot;c:\word letter\graphics\slpcanada2.bmp&quot;) To add a picture
.PageSetup.RightMargin=50 To change the margin setting
.insertbreak() To insert a pagebreak
endwith
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top