Mac Word 365 -- general problem of KM to select certain options

I'm a long time user of KM, but not a "power KM scripter" and I have searched this forum for anyone else who's described a solution.

I can illustrate the problem I'm trying to solve -- with a Word 366 (Mac) document open, create a macro that will toggle the "view hidden text" option.

To do this manually, the sequence is:

  1. Click on the Word menu item.
  2. Click on Preferences.
  3. Click on View.
  4. Click on two check boxes "All" and "Hidden text."
  5. Click on the Red circle to close the Preferences.
  6. Move the mouse back to its original position.

I've tried using Word to record a macro, but this type of action (accessing Preferences) does not record any specific VBA code at all. None. Zip. Nada. :slight_smile:
I also tried recording a Macro using KM, but it seems that the opening of the Preferences window is viewed by KM as a "Resize Front Window to Pixels." The recorded mouse click to click on the View option in preferences is not being recorded the first time I do it, so I have click on View options, then, without moving the mouse, click again (fortunately this is white space on the Preferences window).

Question 1: Why is the first click after the Resize Window action not being recorded? (I can see that this is the problem by perform the actions very slowly and watching the macro actions appear in KM).

QUESTION 2: The "Resize Front Window to Pixels" Action that is recorded in response to the Preferences Window opening up has the unwanted side effect of reducing the size of the main Word window with the document in it. If I make this action inactive, the macro works -- which makes me wonder why KM is recording it?

Thanks in advance

While the Word Preferences window is NOT exposed as an AppleScript object, the settings you want are exposed for each window/document.
So this script will toggle the settings for the current active Word Document:

tell application "Microsoft Word"
  set oWin to window 1
  set oView to view of oWin
  tell oView
    if (show hidden text) then
      set show hidden text to false
      set show hidden text to true
    end if
    if (show all) then
      set show all to false
      set show all to true
    end if
  end tell
end tell

It may be possible to set the Word Preferences using UI scripting, but this is more difficult. Let us know if you really need this.

1 Like