Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Don Worrall
  Where is Don Worrall?
 Yellowknife
 Canada
 Don Worrall
 To: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 Tags
Subject: RE: Word automation problem
Thread ID: 228035 Message ID: 228708 # Views: 1 # Ratings: 0
Version: Visual FoxPro 5 Category: General VFP Topics
Date: Thursday, May 21, 2009 12:37:18 AM         
   


> > When I execute the following code in the Command window it does as expected, i.e. opens BulletinShell.doc, "types" some stuff, saves and closes the document and quits Word (in Office 2000).
> >
> > But exactly the same code executed from a form command button Click method generates this error when it hits loDoc = loWord.Documents.Save: "OLE |Dispatch exception code 0 from Microsoft Word: ?.."
> >
> > loWord = CREATEOBJECT("Word.Application")
> > loDoc = loWord.Documents.Open(LOCFILE("BulletinShell.doc"))
> > loWord.Visible = .T.
> >
> > loWord.Selection.Style = loDoc.Styles("Heading 2")
> >
> > loWord.Selection.TypeText("NT" + CHR(9))
> > * several more line like above
> >
> > loDoc = loWord.Documents.Save
> > loDoc = loWord.Documents.Close
> > loWord.Quit
> >
> > RELEASE loDoc, loWord
> >
> > Any help for this VBA ignoramus would be greatly appreciated.
> >
> > Thanks.
>
> The error is in loDoc.Styles("Heading 2").You must use a word constant and # define.
>
>
> loWord = CREATEOBJECT("Word.Application")
> loDoc = loWord.Documents.Open(LOCFILE(getfile('doc')))
> loWord.Visible = .T.
> #define wdStyleHeading2 -3
> loWord.Selection.Style = loDoc.Styles(wdStyleHeading2)
> 
> loWord.Selection.TypeText("NT" + CHR(9))
> * several more line like above
> 
> loDoc .Save
> loDoc.Close
> loWord.Quit
> RELEASE loDoc, loWord
> 

>
> Dont rate please.its only for the pleasure to help.Give me only a feed back.
> Yousfi Benameur

Thanks Yousfi, but it still doesn't work.

ENTIRE THREAD

Word automation problem Posted by Don Worrall @ 5/14/2009 11:56:42 PM
RE: Word automation problem Posted by Anders Altberg @ 5/15/2009 12:33:55 AM
RE: Word automation problem Posted by Don Worrall @ 5/15/2009 7:32:03 PM
RE: Word automation problem Posted by Anders Altberg @ 5/16/2009 1:05:24 AM
RE: Word automation problem Posted by Don Worrall @ 5/20/2009 7:13:09 PM
RE: Word automation problem Posted by Tamar Granor @ 5/15/2009 10:37:53 PM
RE: Word automation problem Posted by Don Worrall @ 5/16/2009 12:51:10 AM
RE: Word automation problem Posted by Yousfi Benameur @ 5/16/2009 10:10:24 AM
RE: Word automation problem Posted by Don Worrall @ 5/21/2009 12:37:18 AM
RE: Word automation problem Posted by Yousfi Benameur @ 5/21/2009 1:25:17 AM
RE: Word automation problem Posted by Don Worrall @ 5/21/2009 10:19:08 PM