• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Microsoft Word do Visual Basic
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Microsoft Word do Visual Basic


  • Subject: Microsoft Word do Visual Basic
  • From: Simon Forster <email@hidden>
  • Date: Tue, 1 Jul 2003 18:16:07 +0100

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.

  • Follow-Ups:
    • Re: Microsoft Word do Visual Basic
      • From: Paul Berkowitz <email@hidden>
    • Re: Microsoft Word do Visual Basic
      • From: Andrew Oliver <email@hidden>
  • Prev by Date: Open webpage
  • Next by Date: Re: [ANN] Shelp and Comparator (downloads)
  • Previous by thread: Re: Open webpage
  • Next by thread: Re: Microsoft Word do Visual Basic
  • Index(es):
    • Date
    • Thread