Re: Applescripting Office X
Re: Applescripting Office X
- Subject: Re: Applescripting Office X
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 04 Jan 2004 10:31:18 -0800
You shouldn't be using " & vblf & " in VBA. Word (even Win Word) uses
Mac-type carriage returns, not Unix-type or even DOS-type. If these returns
are within text you can use " & vbCr & ". If they're within code but not
literal text then - in the past - a simple line ending is good enough.
I think you must be hitting a new kink using Script Editor 2.0 which uses LF
(ASCII 10) for its line endings. (I work mostly in Script Debugger and keep
to CR - ASCII 13 - for line endings there). Since all 'do Visual Basic'
commands are strings _within AppleScript_, that means that your line endings
are getting transmitted as LF which will be wrong for VBA. I don't quite
follow exactly what you're saying, but I'd suggest running your VB code
through a handler that replaces every line ending not with internal literal
quotes with ' & return & '(NOT inside quotes!!). E.g., if the original VB is
Dim oDoc As Document
Set oDoc = Documents.Add
oDoc.PrintOut
You would write
set vbScript to "Dim oDoc As Document
Set oDoc = Documents.Add
oDoc.PrintOut
"
set vbScript to my ReplaceLineEndings(vbScript)
tell application "Microsoft Word" to do Visual Basic vbScript
on ReplaceLineEndings(someText)
set theLines to paragraphs of someText
set AppleScript's text item delimiters to {return}
set fixedText to theLines as string
set AppleScript's text item delimiters to {""}
return fixedText
end ReplaceLineEndings
That's just a start. You also need the other replacements for internal
quotes and so on which you already have. If the original VB (that works in
VB Editor) contains ' & vbCr & ' you can transcribe those literally. If the
original AppleScript contains line endings within hard-coded literal text,
you need to change those to ' & vbCr & '. (If I remember correctly the only
thing that would need ' & vbLf & ' is text to be displayed in a MsgBox
within Word.)
To avoid the need for the ReplaceLineEndings handler above you could be
using Smile instead of Script Editor 2. Smile will use CR line endings.
I hope this is actually pertinent to your problem, which I don't fully
follow.
--
Paul Berkowitz
>
From: Claude M.CAUWE <email@hidden>
>
Date: Sun, 4 Jan 2004 15:29:45 +0100
>
To: Paul Berkowitz <email@hidden>
>
Cc: AppleScript-Users <email@hidden>
>
Subject: Re: Applescripting Office X
>
>
paul, many thanks for the useful tips.
>
>
I found what I neede (or close to) in your reference documents.
>
>
HOWEVER...
>
>
Soemthing strange keeps on bugging me.
>
>
If I record a VBA script in VBE, and then copy-paste it to AppleScript,
>
most of the time, I will get a Word error stating "Syntax error" in TMP
>
DDE"
>
The offenders being "& vblf &" strings which replace the "carriage
>
return" in Applescript. even stranger, when I copy-paste the VBA in
>
Appelscript and run it immediately, no error warning will happoen.
>
Should I have to modify annything in the Applescript code, then teh "&
>
vblf &"'s are back, and it crashes the execution.
>
>
Would any of you have any idea how to avoid this trouble ?
>
>
MTIA
>
>
Claude
>
>
>
On Jan 3, 2004, at 18:50, Paul Berkowitz wrote:
>
>
> --
>
> Paul Berkowitz
>
>
>
>
>
>> From: "Claude M. CAUWE" <email@hidden>
>
>> Date: Sat, 3 Jan 2004 18:03:36 +0100
>
>> To: <email@hidden>
>
>> Subject: Applescripting Office X
>
>>
>
>> I have lots of trouble porting an lawyer's office administrative
>
>> system
>
>> which relies mainly on a FileMaker set of databases and Applescripts
>
>> transferring names, addresses and case references to MS Word
>
>> (initially
>
>> Office 98) for mail redaction.
>
>>
>
>> In OS 9, simple commands like
>
>>
>
>> tell application "Microsoft Word"
>
>> activate
>
>> set cell 2 of table 1 of front document to customerAddress
>
>> save front document in folderPath & folderName & ":" & saveName
>
>> end tell
>
>>
>
>> worked perfectly. Now, with the upgrade to Panther (and, subsequently
>
>> to Office X), i'm dumped in big trouble because none of the simple
>
>> commands (make new table, set cell .. of table .., etc) works anymore.
>
>>
>
>> For some of them, i for sure can use the "do Visual basic" command,
>
>> followed by the reference of the table to be created.
>
>> But my most important trouble remains to SET the CELLS of the newly
>
>> created table... I need to put variables in these celles, thos
>
>> variables being the names and case references, etc..., which come from
>
>> FileMaker...
>
>
>
> It's all doable via 'do Visual Basic', which is the only way you're
>
> going to
>
> be able to do it in any current version of Word. Unfortunately, it
>
> does mean
>
> learning some of the basics of another scripting language - VBA. The
>
> VBA
>
> Help in Visual Basic Editor is actually very good and you could learn
>
> what
>
> you need to do by following the Help and Examples there. An excellent
>
> primer
>
> is the O'Reilly book "Writing Word Macros": it presents a clear and
>
> orderly
>
> tutorial for learning VBA for Word. It's quite possible to set the
>
> content
>
> of table cells in VBA.
>
>
>
> For some guidance on using 'do Visual Basic', including incorporating
>
> AppleScript variables into 'do Visual Basic' commands, see
>
>
>
> <http://www.mvps.org/word/FAQs/WordMac/WordAppleScript.htm>
>
>
>
> But you have to go there in Internet Explorer - it comes up blank in
>
> Safari.
>
>
>
> For some more advanced examples specifically of using tables in
>
> AppleScript,
>
> you might want to work your way through the 'do Visual Basic' parts of
>
> my
>
> script "Print Tasks Lists", which you can get at
>
>
>
> MacScripter.net <http://macscripter.net/scriptbuilders/>
>
>
>
>>
>
>> Ant help would be grandly appreciated, for no litterature already
>
>> exists on how to Applescript Word X.
>
>
>
> See the web page above.
>
> _______________________________________________
>
> 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.
_______________________________________________
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.