Re: How to call a Word VBA function?
Re: How to call a Word VBA function?
- Subject: Re: How to call a Word VBA function?
- From: Richard Rönnbäck <email@hidden>
- Date: Fri, 16 Jan 2004 20:40:57 +0100
Paul,
Thanks a lot! It will definitely work, and will be an even better option for
other purposes. I was kind of hoping that I wouldn't have to go through a
temp file, but I have searched a long time on various sources, but I can't
find an example that actually does return something to AS
The title of a document is assigned the same value as the first
automatically, but the user can enter anything they like. The title is also
passed along if you do a PDF
I will be getting other attributes as well, such as the author etc, but now
since you gave me a way to get it back that will be smooth sailing :-)
Thanks again
On 04-01-16 19.39, "Paul Berkowitz" <email@hidden> wrote:
>
On 1/16/04 3:26 AM, "Richard Rvnnbdck" <email@hidden> wrote:
>
>
> I am trying to do what I thought shouldn't be that hard but I am now totally
>
> lost.
>
>
>
> I am trying to get the document title from a Microsoft Word X document (the
>
> title you fill in via File>Properties>Summary>Title)
>
>
>
> Since it not exposed to AppleScript I thought I could stitch it together
>
> with VBA, but despite reading Microsoft step by step article
>
>
>
> http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:
>
> 80/support/kb/ARTICLES/Q184/4/40.asp&NoWebContent=1
>
>
>
> over and over again I still don't get it.
>
>
>
> Since I want a value back I assume it must be a function, which is (and it
>
> does seem to work as expected):
>
>
>
> Function GetTitle(strWordTitle As String) As String
>
> Dim dp As Object
>
> Set dp = ActiveDocument.BuiltInDocumentProperties
>
> strWordTitle = dp(wdPropertyTitle)
>
> End Function
>
>
>
>
>
> I have then, with endless variations, tried to call from, and get the value
>
> back to, the AppleScript, but to no avail. It should be something like:
>
>
>
> tell application "Microsoft Word"
>
> tell document 1
>
> do script "GetTitle()"
>
> set myTitle to the result
>
> end tell
>
> end tell
>
>
>
>
>
> Can anyone help me?
>
>
I've never used 'do script' but I have frequently used 'do Visual Basic'.
>
You can't get the result of a VBA Function back to AppleScript in the normal
>
way.
>
>
What you can do is write it to a text file using VB's Open For Output and
>
Print commands (first converting your variables to String if you need to,
>
but that's not an issue here), in a similar manner to AppleScript's open for
>
access and write commands (see below), and then read the file in
>
AppleScript. I do that in the PREFS script for my "Print Tasks List" script
>
you can download from
>
>
MacScripter.net <http://macscripter.net/scriptbuilders/>
>
>
>
e.g.
>
>
-----------------------
>
>
set asTextFilePath to ((path to temporary items as string) & "Shared Text
>
File")
>
>
set vbTextFilePath to "\"" & asTextFilePath & "\""
>
>
tell application "Microsoft Word"
>
>
do Visual Basic "
>
Dim strWordTitle As String
>
Dim dp As Object
>
>
Set dp = ActiveDocument.BuiltInDocumentProperties
>
strWordTitle = dp(wdPropertyTitle)
>
>
'write strWordTitle to text file, replacing any text there
>
FileNumber = FreeFile
>
Open " & vbTextFilePath & " For Output As #FileNumber
>
Print #FileNumber, strWordTitle
>
Close #FileNumber
>
"
>
end tell
>
>
set strWordTitle to paragraph 1 of (read alias asTextFilePath)
>
>
>
-------------------------
>
>
BTW, this wdPropertyTitle constant doesn't seem to correspond with the name
>
of the file but rather with the Title (heading) of the document. I guess
>
that's what you want?
>
>
By making the file in Temporary Items, I don't bother to destroy it after
>
using it (since it will be destroyed when you log out anyway), but you can
>
always do so if you want:
>
>
set posixTextFilePath to POSIX path of asTextFilePath
>
do shell script "rm " & posixTextFilePath
>
--
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.