• 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
Passing String Variables to Visual Basic within Applescript???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Passing String Variables to Visual Basic within Applescript???


  • Subject: Passing String Variables to Visual Basic within Applescript???
  • From: Ian MacLachlan <email@hidden>
  • Date: Sun, 24 Jun 2001 12:07:15 -0700

Help,

I' m putting together a script (droplet) that takes user input
(old_string, new_string) and opens a series of Word Documents and makes
changes to the text using MS Word's replace command.

Question: How do I refer to the string variables captured in the
Applescript section when I initiate the Visual Basic section? The
relevant parts of the script follow. I'll attach the whole thing as
well.
Applescript that gets variables:

display dialog "What text would you would like to remove?" default
answer "Remove this text"
set the old_string to the text returned of the result
set old_string to ((old_string) as text)

display dialog "Any occurance of '" & old_string & "' will be replaced
with?" default answer "Replace with this text"
set the new_string to the text returned of the result
set new_string to ((new_string) as text)

set the response_text to "Any text containing the string '" & the
old_string & "' will be replaced with '" & the new_string & "'."
display dialog response_text buttons {"OK"} default button 1

The section that opens Word and should make the repacements:

on process_item(this_item, old_string, new_string)

-- note that the variable this_item is a reference in alias format
--

tell application "Microsoft Word"
activate
open this_item

-- replace instances in main body
--

do Visual Basic " Selection.Find.ClearFormatting"
do Visual Basic " Selection.Find.Replacement.ClearFormatting"
do Visual Basic " With Selection.Find
.Text = Str(old_string) <---- this
doesn't work!!!!
.Replacement.Text = Str(new_string) <----- this doesn't work
either!!!!!
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With"
do Visual Basic " Selection.Find.Execute Replace:=wdReplaceAll"

-- finish file
--
save document 1 of window 1
close document 1 of window 1
end tell

end process_item

[demime 0.98b removed an attachment of type multipart/appledouble which had a name of Mr Clean3]


  • Follow-Ups:
    • Re: Passing String Variables to Visual Basic within Applescript???
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: Why isn't there a constant called finder?
  • Next by Date: Re: Passing String Variables to Visual Basic within Applescript???
  • Previous by thread: Re: Script Editor lockups?!
  • Next by thread: Re: Passing String Variables to Visual Basic within Applescript???
  • Index(es):
    • Date
    • Thread