Macro to toggle Normal/Web views in Writer?

I’m looking for a macro to toggle between Normal and Web views in Writer. I can do one or the other, but I can’t toggle them both using one macro.

Here’s typical code:

sub Normal_View
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "NormalViewMode"  ' or: "PrintLayout"
args1(0).Value = false   ' seems unnecessary 

dispatcher.executeDispatch(document, ".uno:PrintLayout", "", 0, args1())

end sub


sub Web_View
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "BrowseView"
args1(0).Value = false

dispatcher.executeDispatch(document, ".uno:BrowseView", "", 0, args1())

end Sub

Thank you.

You must write your macros based on the API objects and functions, instead of recording them.
Install and use one of the excellent object inspection tools: the XrayTool or the MRI

xraytool seems to be abandoned. Can’t make any sense of MRI. I was trying to work with the recorded macros as a basis. But it’s not working.

You need use property ShowOnLineLayout

doc = ThisComponent
settings = doc.CurrentController.ViewSettings
settings.ShowOnLineLayout = Not settings.ShowOnLineLayout
1 Like

Truly an amazing macro, for its conciseness.

Thank you very much!