Lightening


I wish to convert a memo field into a Word format document.

I searched around and found this:

oWord=CreateObject("word.application")

oWord.Documents.Open("c:\test.doc")

oWord.ActiveDocument.Range.Start=0

oword.ActiveDocument.Range.End=0

oWord.ActiveDocument.Range.Text="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

oWord.Documents.Save()

It works if the test.doc is already there. How do I create the file using VFP code because the file name should be created by the user himself.

Thanks.




Re: How to create a Word document?

dni


You may try:

STRTOFILE(" ","X.DOC")

File X will be open by word as a empty document.







Re: How to create a Word document?

CDFAUX

Hi.

Instead of .Open you should use:

oWord.NewDocument.Add("c:\test.doc")

Obviously you should replace "c:\test.doc" per a variable that contains the pathname of the document to create.

Saludos!






Re: How to create a Word document?

Lightening

Thank you both.

=filetostr()  does create a word document and it runs fast.

But when you try to open it. you got a prompt to convert and need to install something in Word.

 

If I use Add("x.doc")  && a non-existent file.

I hit an error. OLE IDispath exception code 0 from Microsoft Word:

Word was unable to read this document. It may be corrupt. .....

 

 





Re: How to create a Word document?

dni

I don't have any message in Word. (I am using Word 2000)




Re: How to create a Word document?

Lightening

It seems to work now. I combined your two codes and do like this.

=STRTOFILE(descr,"c:\test.doc") && It can be a variable here.

oWord=CreateObject("word.application")

oWord.Documents.open("c:\test.doc")

oWord.Visible = .T.

Thank you again.





Re: How to create a Word document?

Alex Feldstein

See:

http://fox.wikis.com/wc.dll Wiki~AutomationExamples

for examples.





Re: How to create a Word document?

Lightening

Still need help. If i put in a variable, it stopped working.

It seems filetostr() convert the string to a txt format file.

That's why I got prompt to have a converter installed in Word.





Re: How to create a Word document?

CDFAUX

Try this code:

oWord=CreateObject("word.application")

oWord.Documents.Add

oWord.ActiveDocument.Range.Start=0

oword.ActiveDocument.Range.End=0

oWord.ActiveDocument.Range.Text="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

oWord.ActiveDocument.SaveAs("c:\tmp\xx.doc")

oWord.ActiveDocument.Close

oWord.Quit





Re: How to create a Word document?

dni

Just put a blank first " " (SPACE(1)) for blank document. For a variable you may try

STRTOFILE(variable,"PATH+FILE NAME")

where variable is a string, and your document will have the string on the first line. May be creates a text file, but my "Word" did not show any message; may be because is old.






Re: How to create a Word document?

Lightening

Thank you very much , Alex.

This seems to meet my needs.

use myTable

loWord = CREATEOBJECT("Word.Application")
go top
Do while recno()<10
cString=Allt(title)+chr(13)+chr(10)+chr(13)+allt(descr)
loWord.Documents.Add()
loRange = loWord.ActiveDocument.Range()
loRange.InsertAfter(cString)
loWord.ActiveDocument.SaveAs("c:\temp\"+ALLTRIM(section)+".doc")
* loWord.PrintOut()
Skip
Enddo
loWord.Quit()
release loRange, loWord