Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Show a Microsoft Word application in VFP Form
Message
From
21/04/1998 05:49:38
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00093494
Message ID:
00093602
Views:
32
>Hi,
>I want to create a form in which a user be able to create new or edit old documents using MS Word. When I use a table with GENERAL field I have problem with creating Mail Merge data source.
>
>When I use word.application instead, I have no idea how to make a preview of document(s) in my form.
>
>Can you help me.
In place editing with VFP is so fascinating. To do it with mail merge :
-Create a dummy word doc
-Append general from word doc if going to inplace edit.
-Create an oleboundcontrol with controlsource = yourgenfield
-Now you have a reference to word so you can bind mailmerge data with word commands.
-Dblclick to edit
-You can continue to call word commands with inplace editing.
For examples about creating word doc and mailmerge using OLE automation, besides solution.app, see "Interacting with word using word.basic" in KB\FAQ\Win32api. Commands there are word.basic commands but most work unchanged in word97 too. Further in Word97 you can createobject("word.application") and then use word.basic and VBA commands interchangeably like in the following example :
*!*	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
		.insert(ltrim(str(recno()))+"-"+trim(employee.last_name)+","+employee.first_name+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))
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform