Hotkey Trigger to Customize the Character Set of a Selected Range in Microsoft Excel

I want to modify the character set of a selected area in Microsoft Excel via a hotkey trigger, but it doesn't take effect all the time.

My script is as follows:

tell application "Microsoft Excel"
   tell active sheet
      set name of font object of range selection to "SimSun"
   end tell
end tell

Looking at Excel's dictionary, range selection is a property of a window and not of a sheet.

So

tell application "Microsoft Excel"
	tell active sheet
		set name of font object of range selection to "American Typewriter"
	end tell
end tell

errors and does nothing but

tell application "Microsoft Excel"
	tell window 1
		set name of font object of range selection to "American Typewriter"
	end tell
end tell

works fine. So, assuming your selection is in the frontmost Excel window, try the tell window 1 version.

1 Like

Thank you very much, your method has solved my problem.