Re: Microsoft Word do Visual Basic
Re: Microsoft Word do Visual Basic
- Subject: Re: Microsoft Word do Visual Basic
- From: Andrew Oliver <email@hidden>
- Date: Tue, 01 Jul 2003 11:25:51 -0700
I assume you've encapsulated/escaped all the quote symbols, etc.
Otherwise, AppleScript will interpret the code incorrectly.
Consider the following:
do Visual Basic "sTitle = "Northern Greece" & vbCrLF"
The AppleScript parser will break this down into a number of sections,
namely:
do Visual Basic "sTitle = "
Northern Greece
and
" & vbCrLF"
Which clearly won't work.
Instead you need to escape the internal quote symbols:
do Visual Basic "sTitle = \"Northern Greece\" & vbCrLF"
etc.
Andrew
:)
On 7/1/03 10:16 AM, "Simon Forster" <email@hidden> wrote:
>
Hi
>
>
Somewhat frustrated here as I have a very simple Visual Basic script
>
which runs in Word:Mac v.X Service release 1 without a problem but will
>
not work when called from within AppleScript. (Actually, I have a
>
somewhat more complicated VB Macro which I'm testing in Word and then
>
want to call from within AppleScript).
>
>
I've searched online and I've searched the archives but couldn't see
>
anything which addressed my problem (although I do find the archive
>
search somewhat awkward to use).
>
>
Anyway.
>
>
Simple VB Macro which runs fine (as long as I have a word doc open):
>
>
////////////////////////////////////Word
>
Macro////////////////////////////////////
>
Sub test()
>
>
Dim sTitle As String
>
>
sTitle = "Northern Greece" & vbCrLf
>
>
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
>
>
End Sub
>
////////////////////////////////////Word
>
Macro////////////////////////////////////
>
>
convert this to an AppleScript:
>
>
////////////////////////////////////AppleScript////////////////////////
>
////////////
>
tell application "Microsoft Word"
>
activate
>
do Visual Basic "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"
>
end tell
>
////////////////////////////////////AppleScript////////////////////////
>
////////////
>
>
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?
>
>
Help.
>
>
Please.
>
>
Simon Forster
>
___________________________________________________
>
LDML Ltd, Office One, 16 Canham Road, London, W3 7SR, UK
>
Tel: +44 (0)20 8749 7766 Fax: +44 (0)70 9230 5247
>
___________________________________________________
>
_______________________________________________
>
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.