Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding a Word Bookmark via OLE Automation from Visual F
Message
From
27/03/1998 07:33:41
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00087325
Message ID:
00087605
Views:
44
>Thanks for the help, Cetin. I'll wait patiently for your answer.
>
>Ben Holton
Ben, here is what you have been waiting for :
*!*	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
Reply
Map
View

Click here to load this message in the networking platform