Word and VB

S

Steve Cronin

Folks;

I've poked around a bit and it seems there are some very helpful and
knowledgeable folks here!
Thanks to all of you who are of service!

OK so I'm trying to print using Word from AScript. I have 3 questions.

1) If I use the 'do Visual Basic' construct will that AppleScipt work
with Word v.X AND Word 2004?

2) What I want to do is essentially 'mail-merge' but the user is not
going to be placing merge tags.
They will simply put placeholders that I will substitute with data in
my script. They will be placing the text in normal layout, inside of
textboxes, and inside of tables. Could be some or all of the above.
How do I determine if there are any text boxes and then iterate over
them changing .Text 'abc' to 'xyz'?

3) I've scouted the past postings and I find some code snippets with
both straight AS and then a do VB with an open quote followed by long
paragraphs of VB code and a closing quote.
When I use this construct I always get a compiler error with the text
looking like ""& vbLf &" Dim cellText As String"& vbLf &" Dim i, j
As Integer"& vbLf &" With ActiveDocument.Tables( _
1)"& vbLf &" ...."
It looks like VB takes on a stray 'vbLf' from my ScriptEditor. What am
I doing wrong here?

Thanks for any help!
Steve
 
P

Paul Berkowitz

Folks;

I've poked around a bit and it seems there are some very helpful and
knowledgeable folks here!
Thanks to all of you who are of service!

OK so I'm trying to print using Word from AScript. I have 3 questions.

1) If I use the 'do Visual Basic' construct will that AppleScipt work
with Word v.X AND Word 2004?

Yes, it will. 'do Visual Basic' continues to work in Word 2004 just like it
did in previous versions.
2) What I want to do is essentially 'mail-merge' but the user is not
going to be placing merge tags.
They will simply put placeholders that I will substitute with data in
my script. They will be placing the text in normal layout, inside of
textboxes, and inside of tables. Could be some or all of the above.
How do I determine if there are any text boxes and then iterate over
them changing .Text 'abc' to 'xyz'?

If you're planning to do this using 'do Visual Basic', why don't you ask in
the microsoft.public.word.vba.general newsgroup for the VBA code? They're
bug VBA experts there. Then just put it into a 'do Visual Basic' command
following the guidelines at http://word.mvps.org/mac/Applescript-VBA.html
3) I've scouted the past postings and I find some code snippets with
both straight AS and then a do VB with an open quote followed by long
paragraphs of VB code and a closing quote.
When I use this construct I always get a compiler error with the text
looking like ""& vbLf &" Dim cellText As String"& vbLf &" Dim i, j
As Integer"& vbLf &" With ActiveDocument.Tables( _
1)"& vbLf &" ...."
It looks like VB takes on a stray 'vbLf' from my ScriptEditor. What am
I doing wrong here?

You're using Script Editor 2.x in OS X (10.3 or later). It's a Cocoa app, so
its line endings are all Unix linefeeds (LF) which VBA calls 'vbLf'. VBA
uses carriage returns (CR) which it knows as 'vbCr'. That webpage on VBA
and AppleScript should probably be updated to included that info. The
scripts you're looking at for models would have been made either with the
older carbon Script Editor or with (the expensive) Script Debugger which can
do CR line endings.

If you're not blessed with Script Debugger (which can be set to use "Mac CR"
endings, even in compiled scripts, after saving them first as Text), you
will have to run your script through a handler that replaces the LF line
endings with carriage returns. Do it this way:

set vbScript to "Type out your VB Code here
Within quotes, as text
Complete with normal line endings
etc.
etc.
etc.
"

set vbScript to my ConvertLineEndings(vbScript)

tell app "Microsoft Word"
do Visual Basic vbScript
end tell


to ConvertLineEndings(vbScript)
set scriptParas to paragraphs of vbScript
set AppleScript's text item delimiters to {return}
set vbScript to scriptParas as string
set AppleScript's text item delimiters to {""}
return vbScript
end ConvertLineEndings



---------------------

You could also use this subroutine to double up "" marks as needed, and so
on, thoughit gets a bit tricky (you need to escape those as \"\" -- see the
webpage.)


--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top