Property or method not found: ViewSettings

Why does my macro display this BASIC runtime error message: Property or method not found: ViewSettings.

I am trying to show the grid lines on Sheet1 and not show them on all other sheets

Sub ShowGridlinesOnlyOnSheet1
    Dim oDoc As Object
    Dim oSheets As Object
    Dim oSheet As Object
    Dim i As Integer

    oDoc = ThisComponent
    oSheets = oDoc.Sheets

    For i = 0 To oSheets.getCount() - 1
        oSheet = oSheets.getByIndex(i)
        If oSheet.Name = "Sheet1" Then
            oSheet.ViewSettings.ShowGrid = True    'This is where the error occurs
        Else
            oSheet.ViewSettings.ShowGrid = False
        End If
    Next i
End Sub

Because your AI hallucinates property ViewSettings.

	doc = ThisComponent
	doc.CurrentController.ShowGrid = True
1 Like

Is it not possible to have ShowGrid set as sheet specific? As this example applies to all sheets and I only want it applied to one sheet, not all.

Ok, how about doing doc.CurrentController.ShowGrid = False for all sheets, activate the first sheet and do “.uno:ToggleSheetGrid” for it?

When I use “View Grid Lines” from Calc 25.2 View menu it is sheet specific, but I just can’t find or create some macro code to accomplish this.

I don’t know such code either. So I just turned on the macro recorder, executed the command and got:

Sub ToggleSheetGrid
Dim document   As Object 
Dim dispatcher As Object 
	document   = ThisComponent.CurrentController.Frame
	dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	dispatcher.executeDispatch(document, ".uno:ToggleSheetGrid", "", 0, Array())
End Sub 

@JohnSUN what you found is the only available way to access the SetShowGrid function in core.

Well, to be fair, it’s not the only way. I could unzip the file, get into settings.xml, find ShowGrid and change it, pack it back… Luckily, like any normal programmer, I’m lazy enough to do such nonsense.

1 Like

See also this topic.