ActiveX/Optcl examples?

50 views
Skip to first unread message

Leslie Brooks

unread,
Jul 12, 2001, 5:04:19 PM7/12/01
to
Does anyone have ActiveX/Optcl examples that they would be willing to
share? Examples of automating Microsoft Word would be particularly
appreciated. The Optcl distribution has a couple of examples but they
are very limited.

Leslie

Leslie Brooks

unread,
Jul 24, 2001, 9:53:52 AM7/24/01
to
leslie...@my-deja.com (Leslie Brooks) wrote in message news:<fc7de112.01071...@posting.google.com>...

For anyone wanting to use Optcl as an ActiveX interface, I have
found the "Microsoft Office 2000 Developer's Guide", by D.F. Scott
quite helpful in explaining what some of the methods and properties
are for and how they work. I have figured out a few things - here is
an example I am working on:

package require optcl

# Start Microsoft Word
#
set word [optcl::new word.application]
#
# Create a new document
#
set doc [$word -with documents add]
#
# Make Word visible (if you don't do this then there won't be a button
# for this document on the Task Bar. The example will still work.)
#
$word : visible 1
#
# Open a new TK window that allows the programmer to browse the Word
type
# hierarchy
#
tlview::viewtype [ optcl::class $doc ]
#
# Read in a template file (that might have formatting already set up.)
# We now have 2 files open.
#
set doc [$word -with documents open "d:\\Tcl\\scripts\\template.doc"]
#
# Insert some text, with formatting
#
$word -with selection.font : name "Courier New"
$word -with selection.font : size 10.0
$doc -with content : text "This text is in Courier 10 point.\r"

#
# Change the first word to Blue text
#
$word -with selection : start 0
$word -with selection : end 5
$word -with selection.font : color wdcolorblue

#
# Change the next word to Bold text
#
$word -with selection : start 5
$word -with selection : end 10
$word -with selection.font : bold 1

# Move the start of the selection to the end so we can insert more
# text (otherwise we would just overwrite the existing text). We
# can move to the end by setting the end to some impossibly large
# value; Word will set it to the real end. Then we set the start
# equal to the end.

$word -with selection : end 50000
set end [$word -with selection : end]
$word -with selection : start $end

$word -with selection.font : name "Courier New"
$word -with selection.font : size 14.0
$word -with selection.range : text "This text is in Courier 14 point."

#
# Save the results under a new filename.
#
$doc saveas "d:\\Tcl\\scripts\\foo.doc"

I have _not_ figured out how to call the Dispatch interface - if
anyone knows the answer to that please let me know. (For example
'headerfooter' is in the dispatch interface - how do you set headers
and footers in Word via Optcl?) I will post an update to this example
when I have enough useful improvements.

Leslie

Rob Barris

unread,
Aug 7, 2001, 4:53:50 PM8/7/01
to
In article <fc7de112.01072...@posting.google.com>,
leslie...@my-deja.com (Leslie Brooks) wrote:


Have you any examples showing how to interface optcl with MSVC++ /
Visual Studio?

Examples: open a project, query name/path of open project, set
configuration, build project, etc.

Rob

Reply all
Reply to author
Forward
0 new messages