Controlling the VBE via Applescript

K

Kristina Conceicao

I'd like to use Applescript to create a new public sub in the Word 98
VBE. I see lots of posts on how to *execute* VBA commands via
Applescript, but nothing on actually creating a sub.

The problem I'm trying to solve is the distribution of macros to my end
users. In Excel, it's easy enough to just create and distribute an
Addin. In Word, I've resorted to putting the code in a document that I
put in the users' Startup folder, or walking them through going into the
VBE and copying/pasting the code from the body of an e-mail. Neither
option is very convenient. I'm thinking that I could create a module in
everyone's Normal template, named "KCcode". Then an Applescript could
add a sub to the module, and save the Normal template.

Any ideas on how I could accomplish this would be much appreciated.
 
P

Paul Berkowitz

I'd like to use Applescript to create a new public sub in the Word 98
VBE. I see lots of posts on how to *execute* VBA commands via
Applescript, but nothing on actually creating a sub.

The problem I'm trying to solve is the distribution of macros to my end
users. In Excel, it's easy enough to just create and distribute an
Addin. In Word, I've resorted to putting the code in a document that I
put in the users' Startup folder, or walking them through going into the
VBE and copying/pasting the code from the body of an e-mail. Neither
option is very convenient. I'm thinking that I could create a module in
everyone's Normal template, named "KCcode". Then an Applescript could
add a sub to the module, and save the Normal template.

Any ideas on how I could accomplish this would be much appreciated.

Don't even think about it in Word 98. Word 98's AppleScript is too buggy -
Word will start crashing within minutes of using almost any commands other
than basic 'activate' or 'open'. Or 'do visual basic', which works fine. But
even in Word 2004, I doubt that you could enter text in a module in VB
Editor, since it's not actually a document. I'll give it a try some day when
I have time.

Yes, you should put the code in a template to be placed in the users'
Startup:Word: folder. There's no reason why you can't install that template
by AppleScript, at least for all users that haven't moved their internal
folders around. In AppleScript, you can find out where the Word application
is using the Finder's 'application file id "MSWD" ' command and get its
container (the Microsoft Office 98 folder), then the Office:Startup:Word
subfolders within, at least if you know the language of the Office
installation. Or using 'do visual basic' you can find out where the Startup
location is. Then, still using the Finder, move the template there.

--
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.
 
K

Kristina Conceicao

Paul said:
Don't even think about it in Word 98. Word 98's AppleScript is too buggy -
Word will start crashing within minutes of using almost any commands other
than basic 'activate' or 'open'. Or 'do visual basic', which works fine. But
even in Word 2004, I doubt that you could enter text in a module in VB
Editor, since it's not actually a document. I'll give it a try some day when
I have time.

Yes, you should put the code in a template to be placed in the users'
Startup:Word: folder. There's no reason why you can't install that template
by AppleScript, at least for all users that haven't moved their internal
folders around. In AppleScript, you can find out where the Word application
is using the Finder's 'application file id "MSWD" ' command and get its
container (the Microsoft Office 98 folder), then the Office:Startup:Word
subfolders within, at least if you know the language of the Office
installation. Or using 'do visual basic' you can find out where the Startup
location is. Then, still using the Finder, move the template there.

Thank you, Paul, for your quick response. I'll try using AppleScript ot
install the template, as you suggested. One more question: will there
be any special considerations if the user is running Word 98 via
Classic? Right now all the end users are in OS 9, but we're upgrading
them to OS X very soon.
 
P

Paul Berkowitz

Thank you, Paul, for your quick response. I'll try using AppleScript ot
install the template, as you suggested. One more question: will there
be any special considerations if the user is running Word 98 via
Classic? Right now all the end users are in OS 9, but we're upgrading
them to OS X very soon.

No, it shouldn't make any difference, except that Microsoft Office 98 folder
will live in the /Applications (Mac OS 9)/ folder, whereas any user who has
Office v, X or 2004 will have the relevant folder in /Applications.
(Personally, I keep my Startup folder in ~/Documents/Microsoft User Data/
folder, with an alias to it in the default location in the Office subfolder.
If you did that with everyone, you'd never have to think about where to
install the template: it would be the same for everyone.)

--
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