Re: Scripting MS Word
Re: Scripting MS Word
- Subject: Re: Scripting MS Word
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 26 Mar 2001 13:06:10 -0800
On 3/19/01 2:07 PM, "Giles Rowland" <email@hidden> wrote:
>
Hello there.
>
>
I am just starting to get my hands dirty with AppleScript, and I'm running
>
into some trouble scripting Word.
>
>
I want to present the user with a save as dialog in Word, so they can choose
>
their own filename and location for the current document. Scripting MS apps
>
seems to involve "Do Visual Basic" steps, but so far my attempts at
>
recording and editing these result in errors, either in AppleScript or
>
Visual Basic.
>
>
Can anyone point me in the direction of an appropriate script step to prompt
>
a Word save as dialog.
Read up on Dialog in the Visual basic Word Help. (Make sure you have
installed Programmability from the Value pack on your Office CD, then go to
Tools--> Macro --> Visual basic Editor, then Help --> Contents & Index when
you get there.)
tell application "Microsoft Word"
activate
do Visual Basic "Dialogs(wdDialogFileSaveAs).Show"
end tell
>
>
I also need to return the filename and location to AppleScript. Any ideas
>
how I should do this?
>
Since applescript doesn't seem to be able to access the same clipboard as
Visaul basic (neither through Word's 'clipboard' in its own dictionary nor
through an osax), you could get it within VB as
ActiveDocument.FullName
and write it to a text file in Temporary Items or elsewhere, then read the
file in applescript. But you don't need to.: just get the name of document 1
in applescript and that gives you the full file-path including folder and
file name . Parse it how you like. So foe example, your full scrip could be:
tell application "Microsoft Word"
activate
do Visual Basic "Dialogs(wdDialogFileSaveAs).Show"
set filePath to name of document 1
end tell
set theFile to alias filePath
set AppleScript's text item delimiters to {":"}
set fileName to text item -1 of filePath
set folderPath to ((text items 1 thru -2 of filePath) as string) & ":"
set AppleScript's text item delimiters to {""}
set theFolder to alias folderPath
end tell
-------
Pick what you need out of those items.
--
Paul Berkowitz