Re: do visual basic - compile Error
Re: do visual basic - compile Error
- Subject: Re: do visual basic - compile Error
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 30 Dec 2004 07:12:37 -0800
It's because you're compiling your code in Script Editor 2.0 which uses Unix
LF line-endings. Since the VB code has to be presented as a string for
AppleScript ('do Visual Basic' command takes a string) those LFs have become
coded into the script in the literal string. Word, on the other hand,
expects CR line endings both within text and between lines of VBA code.
(Word differs from Windows text files.) You can see it's complaining about
all those 'vbLf' characters - that's a constant for LF character (i.e.
Chr(10)). It wants CRs instead. So what you need to do is use the 'return'
AppleScript constant to replace the LFs with CRs. Instead of saying 'as
string' (it already is a string), try this:
set xVBcode2 to "
Dim datField As Field
Dim n As Integer
Dim i As Integer
Dim docParFormat As ParagraphFormat
"
set xVBcode2 to my ConvertForVB(xVBcode2)
tell application "Microsoft Word"
-- no need to activate
do Visual Basic xVBcode2
end tell
on ConvertForVB(vbText)
set theLines to paragraphs of vbText
set AppleScript's text item delimiters to {return}
set vbText to theLines as string
set AppleScript's text item delimiters to {""}
return vbText
end ConvertForVB(vbText)
---------------
Use that handler every time you need to use 'do Visual Basic'. It's easier
to write and to read than putting ' & return & ' in run-on text without line
endings.
--
Paul Berkowitz
> From: Armin Egginger <email@hidden>
> Date: Thu, 30 Dec 2004 12:17:25 +0100
> To: <email@hidden>
> Subject: do visual basic - compile Error
>
> Dear Scripters,
>
> I need a AppleScript for word with a more functions. So I've checked VB
> and recorded a macro and change some parts of it. The VB script works
> fine in the app 'Word' directly. Now I put the VB in my AppleScript and
> get an error by running the script.
> I get the error in 'Word', if there is a carriage return in the VB
> Text. Also simple VB commands gets a error. One line VB sripts without
> CR works, but I have several lines in my script.
>
> Any ideas?
>
> Armin
>
> Tested on:
> Mac OS X.3.7 german, Word v.X (incl Security Update) english Version,
> AS 2.0 (v43) 1.9.3
> Mac OS X.3.7 german, Word v.X (incl Security Update) german Version, ,
> AS 2.0 (v43) 1.9.3
>
>
> ============================
> my script
>
> set xVBcode2 to "
> Dim datField As Field
> Dim n As Integer
> Dim i As Integer
> Dim docParFormat As ParagraphFormat
> " as string
>
> tell application "Microsoft Word"
> activate
> do Visual Basic xVBcode2
> end tell
>
> ============================
> ERROR in Word "compile Error"
> Sub TmpDDE()
> "& vbLf &"Dim datField As Field"& vbLf &"Dim n As Integer"& vbLf
> &"Dim i As Integer"& vbLf &"Dim docParFormat _
> As ParagraphFormat
>
> End Sub
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Applescript-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden