Re: Microsoft Word do Visual Basic
Re: Microsoft Word do Visual Basic
- Subject: Re: Microsoft Word do Visual Basic
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 01 Jul 2003 11:38:13 -0700
On 7/1/03 10:16 AM, "Simon Forster" <email@hidden> wrote:
>
When run with a Word doc open this AppleScript fails. The debugger
>
throws the error:
>
>
////////////////////////////////////VB
>
Error////////////////////////////////////
>
Sub TmpDDE()
>
Dim sTitle As String"& vbLf &"sTitle = "This is a string in Skia
>
bold""& vbLf &"Selection. _
>
InsertAfter Text:=sTitle"& vbLf &"With Selection.Font"& vbLf &"
>
.Name = "Skia""& vbLf &" . _
>
Size = 12"& vbLf &" .Bold = True"& vbLf &" .SmallCaps =
>
True"& vbLf &"End With"& vbLf &"With Selection. _
>
ParagraphFormat"& vbLf &" .LineSpacingRule =
>
wdLineSpace1pt5"& vbLf &" .Alignment = _
>
wdAlignParagraphCenter"& vbLf &"End With"& vbLf
>
&"Selection.Collapse Direction:= _
>
wdCollapseEnd
>
End Sub
>
////////////////////////////////////VB
>
Error////////////////////////////////////
>
>
I can run 1 line "do Visual Basic" commands without a problem but as
>
soon as I have a second line, the "do Visual Basic" script step fails.
>
I've been playing with this for circa 4 hours now and I cannot find any
>
sensible reference online anywhere. All indications are that this
>
AppleScript should run fine but not for me. Why not? What am I doing
>
wrong?
The VBA compiler seems to be reading your line endings as Unix-type
linefeeds, known to VBA as the constant 'vbLf'. It wants CR carriage returns
for line separators.
This looks like a new issue resulting from using the beta v2.0 Script
Editor, which is Cocoa and must be using LF line-endings. Is that what
you're using? (AppleScript itself is now agnostic about line endings: it
will read CR, LF and CRLF all as paragraph terminators.)
You could use Smile or Script Debugger or the old carbon Script Editor. Or
you could run your script text through a tids converter first:
----------UNTESTED--------------
set vbScript to "Dim sTitle As String
sTitle = \"This is a string in Skia bold\"
Selection.InsertAfter Text:=sTitle
With Selection.Font
.Name = \"Skia\"
.Size = 12
.Bold = True
.SmallCaps = True
End With
With Selection.ParagraphFormat
.LineSpacingRule = wdLineSpace1pt5
.Alignment = wdAlignParagraphCenter
End With
Selection.Collapse Direction:=wdCollapseEnd
"
set vbScript to FixLineEndings(vbScript)
tell app "Microsoft Word" to do Visual Basic vbScript
to FixLineEndings(someText)
set paraList to paragraphs of someText -- catches LFs
set AppleScript's text item delimters to return -- i.e. CR
set someText to paraList as string
set AppleScript's text item delimters to {""} -- default
return someText
end FixLineEndings
----------------------------------------
For some other issues in using 'do Visual Basic' see
http://www.mvps.org/word/FAQs/WordMac/WordAppleScript.htm
--
Paul Berkowitz
_______________________________________________
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.