Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word 97 document
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00145212
Message ID:
00145233
Views:
31
>Is there a way to create a new document in word from VFP with a preselected file name ? In the following code :
>
>x = CreateObject('Word.Application')
>x.Documents.Add
>x.Visible = .t.
>
>a new doc is created, how can I create the file name for the doc or force it to be saved as a name and location I assign ? Is there documentaion for actions of Documents, I am familiar with Add and Open, but what else is available for manipulation of word 97 from
>VFP ?
>
>TIA !! CB

Hi Clark,

I've got several samples on my website that show how to do a lot of this. You might want to download them. If you're using VFP 6 you can now do the vba print and save, otherwise you can call word.basic methods to do whats needed. You don't have to instance another object either. Here's a snipped of some code I used for a project recently which should be useful. I created the form with bookmarks and saved it as a template.
#define true .t.
#define false .f.
#define cr chr(13)
use test
go top
oword=create('word.application')
if not file('d:\vfplibrary\word\affidavit of complaint.dot')
 wrdfile=getf('','Affidavit','Get')
else
wrdfile='d:\vfplibrary\word\affidavit of complaint.dot'
endif
oword.documents.open(wrdfile)
oword.caption='Word97 Affidavit'
lcoffense=offense
lcdefendant=allt(def_fname)+' '+allt(def_lname)
lcaction='arrest'
if def_sex $'Mm'
 lchimher='him'
 else
 lchimer='her'
endif
oword.ACTIVEDOCUMENT.Bookmarks("AFFIANT1").SELECT
oword.SELECTION.insertafter(affiant)

oword.ACTIVEDOCUMENT.Bookmarks("AFFIANT1ADDRESS").SELECT
oword.SELECTION.insertafter(aff_addres)
***************
oword.ACTIVEDOCUMENT.Bookmarks("warrantoffense").SELECT
oword.SELECTION.insertafter(lcoffense)
******************************
Application.top = 140
Application.left = 245
Application.width = 380
Application.height = 270
oword.top = 1
oword.left = 1
oword.width = 180
oword.height = 260
oword.visible= .t.
*oword.activedocument.CheckSpelling
application.visible= .t.
**** Currently you have to use wordbasic to do the printing.
**** vba's print method isn't supported in versions prior to VFP 6.
**** However, vba print preview is . . .
*Oword.activedocument.PrintPreview
*** print the current document
cMessageTitle = 'Print?'
cMessageText = 'Print this document?'
nDialogType = 4 + 32 + 256
*  4 = Yes and No buttons
*  32 = Question mark icon
*  256 = Second button is default
nAnswer = MESSAGEBOX(cMessageText, nDialogType, cMessageTitle)
if nanswer=7
 llprint=.f.
 else
 llprint=.t.
endif

if llprint
oWord.WordBasic.FilePrint(.t.,,,,,,,1)
endif
**** Currently you have to use wordbasic to save the file.
**** vba's saveas and save methods aren't supported.
*** save the file as whatever
cMessageTitle = 'Save?'
cMessageText = 'Save this document?'
nDialogType = 4 + 32 + 256
*  4 = Yes and No buttons
*  32 = Question mark icon
*  256 = Second button is default
nAnswer = MESSAGEBOX(cMessageText, nDialogType, cMessageTitle)
if nanswer=7
 llsave=.f.
 else
 llsave=.t.
endif
*!*	For this demo I'm saving the file dynamically by using the 
*!*	system time as the file name and storing it in the root directory
*!*	of the c: drive.  Make your adjustments to suit your needs.
if llsave
lcfile='c:\'+AFFTEST.DOC'
oword.wordbasic.filesaveas(lcfile)
endif
John Harvey
Shelbynet.com

"I'm addicted to placebos. I could quit, but it wouldn't matter." Stephen Wright
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform