Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Mail Merge
Message
De
27/10/1998 06:23:36
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
27/10/1998 04:15:01
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00150811
Message ID:
00150825
Vues:
12
>Using GETOBJECT to launch Word - where and how do I use this, i.e. on a command button on a form? I've tried this but it doesnt launch Word. Any ideas/help please

Bob,
To launch word you could either use getobject or createobject. It could be done programmatically (no form I mean) or with a form. And either with an embedded/linked doc or purely separate :
create cursor wtest (wf g)
append blank
append general wf from ("c:\my documents\cetins11.doc")
oform = createobject("form")
with oForm
	.addobject("olbW","Oleboundcontrol")
	.height = 420
	.width = 620
	with .olbW
		.top = 10
		.left = 10
		.height = 400
		.width = 600
		.controlsource = "wtest.wf"    		&& Embedded word doc
		.object.saveas("c:\temp\savedfromgen.doc")  && saved to disk
	endwith	
	.removeobject("olbW")
	.AddObject('cmdCommand1','cmdMyCmdBtn')  && Add Command button
	.AddObject("oleObject","oleWordObject")  && Add OLE object
	.cmdCommand1.Visible=.T.			&& Display the "Quit" Command button
	.oleObject.DoVerb(-1)				&& -1 for Edit
	.Show								&& Display the form
endwith	
READ EVENTS	&& Start event processing

DEFINE CLASS oleWordObject as OLEControl
	OleClass ="Word.document.8"			&& Server name
	OleTypeAllowed = 0 					&& Linked
	DocumentFile = "C:\temp\savedfromgen.doc"	&& This file would be created from embedded
ENDDEFINE

DEFINE CLASS cmdMyCmdBtn AS CommandButton  && Create Command button
	Caption = '\<Quit'  && Caption on the Command button
	Cancel = .T.  && Default Cancel Command button (Esc)
	Left = 1  && Command button column

	Top = 1  && Command button row
	Height = 25  && Command button height

	PROCEDURE Click
		CLEAR EVENTS  && Stop event processing, close form
ENDDEFINE
This one demonstrates launching word and talking to it via both Word.basic and vba (Word95 only use word.basic) :
*!*	This example inserts first 10 recs from employee table
*!*	Bookmarks each as inserted
*!*	Moves odd recno() records to eof
*!*	Please notice that this is for word97
*!*	Word.basic commands work unchanged in word95 & word97 (Those used here)
*!*	Some sections are commented to show the same syntax (or alternative)
*!*	for VB and wordbasic

#define NL chr(13)
PUBLIC oWordDocument

*** set the LOCALEID to English
nlLocaleId=sys(3004)		&& Save local id
=sys(3006,1033)				&& We will be sending instructions in English 
use home()+"samples\data\employee"		&& test table
wait window nowait "Creating Word Document..."

oWordDocument=createobject("word.application")	&& Create word object
with oWordDocument.wordbasic
	.appshow							&& Show word app
	.filenewdefault        				&& New file, default template
	scan while recno() <= 10
		.formatfont(12,,6)					&& 12 points, red
		.editbookmark("b"+alltrim(employee.emp_id),,1)   && Add bookmark using emp_id
		* oWordDocument.activedocument.bookmarks.add(cBookmark) - VB syntax
		lcBkmark = "b"+alltrim(employee.emp_id)
		lcBkmarkvalue = ltrim(str(recno()))+"-"+trim(employee.last_name)+","+employee.first_name
		? lcBkmark, lcBkmarkValue
		.setformresult(lcBkmark,lcBkmarkValue)
		.insert(NL) 
		* Insert employee name - recno is just for us to track
		.formatfont(10,,5)					&& 10 points, Magenta
		.insert(employee.notes+NL+NL)  		&& Insert employee notes
		* Insert odd recs as selstart, even as selend into an array
		if recno()%2 = 1
			dimension aBookMarksRange[;
				iif(type("aBookMarksRange")="U",1,;
					alen(aBookMarksRange,1)+1),2]
		endif
		store "b"+alltrim(employee.emp_id) to ;
				("aBookMarksRange[alen(aBookMarksRange,1),"+iif(recno()%2=1,"1","2")+"]")
	endscan
endwith
if type("aBookMarksRange")#"U"		&& Make sure bookmark array exist
	with oWordDocument.ActiveDocument  && Use VB syntax instead of wordbasic
		for ix=1 to alen(aBookMarksRange,1)
			if .Bookmarks.exists(aBookMarksRange[ix,1]) ;
				and .Bookmarks.exists(aBookMarksRange[ix,2]) && Are they both defined ?

				.Range(.Bookmarks(aBookMarksRange[ix,1]).Range.Start, ;
					    .Bookmarks(aBookMarksRange[ix,2]).Range.End).cut && Select & cut range
*!*					.Range(.Bookmarks(aBookMarksRange[ix,1]).Range.Start, ;
*!*						    .Bookmarks(aBookMarksRange[ix,2]).Range.End).select && Select range
*!*					oWordDocument.Selection.Cut					&& Cut selection
				oWordDocument.Selection.Goto(-1,,,"\EndOfDoc")	 && VB goto bookmark   
				oWordDocument.Selection.Paste
* Same word.basic way to cut and paste				
*!*					oWordDocument.wordbasic.editcut    		&& Wordbasic cut method
*!*					oWordDocument.wordbasic.endofdocument   && Wordbasic goto eod
*!*					oWordDocument.wordbasic.editpaste    	&& Wordbasic paste method
			endif	
		endfor
	endwith
endif	
wait clear
**** Set the LocaleId to the previous value
=sys(3006,val(nlLocaleId))
If you want all these for mailmerging take a look at MailMerge class in files\classes section.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform