Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
833 views
in Technique[技术] by (71.8m points)

excel - The MacScript function is not working well in Office for Mac 2016! Any ideas?

My macros use MacScript heavily, but it doesn't seem to be working in any of latest Office for Mac 2016 preview builds

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The MacScript command, used to support inline Apple Scripts in Office for Mac 2011, is being deprecated. Due to restrictions of the sandbox, the MacScript command can no longer invoke other applications such as the Finder. Therefore we discourage the use of this command.

For cases which require changing your existing code so it doesn’t use MacScript, you can use the AppleScriptTask command (see below).

The new AppleScriptTask command executes an AppleScript script. This similar to the MacScript command except that it runs an AppleScript file located outside the sandboxed app. Call AppleScriptTask as follows:

 Dim myScriptResult as String

?myScriptResult = AppleScriptTask ("MyAppleScriptFile.applescript", "myapplescripthandler", "my parameter string") 

Where:

  • The “MyAppleScript.applescript” file must be in ~/Library/Application Scripts/[bundle id]/, the extension applescript is not mandatory, .scpt may also be used
  • “myapplescripthandler” is the name of a script handler in the MyAppleScript.applescript file
  • “my parameter string” is the single input parameter to the “myapplescripthandler” script handler.
  • The corresponding AppleScript for Excel would be in a file named "MyAppleScriptFile.applescript" that is in ~/Library/Application Scripts/com.microsoft.Excel/

Note: The [bundle id]s for Mac Word, Excel and PowerPoint are:

  • com.microsoft.Word
  • com.microsoft.Excel
  • com.microsoft.Powerpoint

An example of a handler is as follows:

on myapplescripthandler(paramString) 

    #do something with paramString 
????return "You told me " & paramString 

end myapplescripthandler

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...