Hi!
I am writing document template script with AppleScript hoping it eventually will work with both Word 2004 and 2008. I am using property fields filling them with data from variables from the script. Then I am updating the property fields with the command
"update field every field of active document"
This updates all the fields in the main document, but not the fields in the header and footer. I have tried several different solutions and none has worked so far. I would really appreciate some help on how to update fields in the header and footer as well.
Convert this to AppleScript....
Public Sub FieldsUpdateAll()
Dim FieldID As Long
Dim aStory As Range
For Each aStory In ActiveDocument.StoryRanges
FieldID = aStory.Fields.Update
If FieldID <> 0 Then
aStory.Fields(FieldID).Select
MsgBox "Field " & aStory.Fields(FieldID).Code.Text & _
" has an error", vbExclamation
End
End If
Next ' aStory
End Sub
On 14/3/08 12:30 AM, in article ee93b...@webcrossing.caR9absDaxw,
"pej...@officeformac.com" <pej...@officeformac.com> wrote:
--
Don't wait for your answer, click here: http://www.word.mvps.org/
Please reply in the group. Please do NOT email me unless I ask you to.
John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
http://jgmcghie.fastmail.com.au/
Sydney, Australia. S33°53'34.20 E151°14'54.50
+61 4 1209 1410, mailto:jo...@mcghie.name
Are you saying that in AppleScript, you do not have to iterate the headers
and footers?
In VBA, there will potentially be six header and footer "stories" per
section, and potentially 255 Sections per document :-)
I know nothing about AppleScript, so I don't understand how your script
handles that?
Cheers
On 15/3/08 2:50 AM, in article C40001F1.2AAF%sha...@NOSPAM.microsoft.com,
"Shawn Larson [MSFT]" <sha...@NOSPAM.microsoft.com> wrote:
> Word uses a Śstoryą concept. Different parts of a document are considered a
> Śstoryą and need to be referenced individually. For example there is a main
> document story, a header/footer story, a footnote story and so on. To
> update the fields within a header, the header needs to be referenced. To
> add another wrinkle, the header Śobjectą within AppleScript does not contain
> fields, but it does contain a Śtext objectą. The text object does contain
> fields, so we need to reference that text object so we can access the
> fields.
>
> So here is a small AppleScript example to update all the fields in the main
> header and in the current document:
>
> tell application "Microsoft Word"
> -- Get a reference to the main header in the current document
> set refHeader to get header of section 1 of active document index header
> footer primary
> -- Update every field in the header
> update field (every field of text object of refHeader)
> -- Update every field in the document
> update field every field of active document
> end tell
>
> HTH,
> Shawn Larson
> Mac Word Test
> Microsoft MacBU
--
That example really solved my problem. Since my headers and footers were first page ones I only changed the reference to the first page headers and footers instead and it works just great! Now all that remains for me is to convert this macro from "vanilla" AppleScript into AppleScript studio. We will see how that works. But there is no way to embed the scripts in to Word like you do with the macros? They have to be separate applications that run outside of Word and tells Word what to do?
All the best
Peter Johansson
Another question (perhaps I should have started a new thread). Anyway, I have read the AppleScript reference guide, but I still don't get how I get Word to open a new document based on a template. As of now the template is located inside my XCode package. As I understand I must install it on in the template folder before I can open it or? Then there was something about accessing it with index numbers?
Either I write the script so it installs this file so word can open a new document based on it or I just want to open a new file based on this document template. I would really appreciate a bit of sample code on how to open a new document based on a template file.
Best wishes
Peter Johansson
Thanks for the quick reply. I did not manage to make the "create new document" command to work. It does not compile and stops at "new" saying "Expected end of line, etc. but found identifier". What did I do wrong?
Best wishes
Peter Johansson
Yes, I am using Word 2004. That is also why I previously was asking on how to access the script from within Word, since the 2004 version does not have an AppleScript menu. I want this script to be compatible with both 2004 and 2008 versions of Word since it is a document template macro that will "replace" the VBA one that is available for Windows.
Best wishes
Peter Johansson