• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 58
  • Last Modified:

DisplayGridlines = True

I want to enable the gridlines w/o enabling the sheet.  Do I have to activate the sheet before I update the gridline property ?

'this works.
    ThisWorkbook.Sheets(1).Activate
    ActiveWindow.DisplayGridlines = True

'why can't I just do this ?
ThisWorkbook.Sheets(1).DisplayGridlines = True
0
sidwelle
Asked:
sidwelle
  • 3
  • 2
  • 2
3 Solutions
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
That's right. You will need to activate the Sheet for enabling or disabling the gridlines because Gridlines is the property of ActiveWindow.
0
 
Roy CoxGroup Finance ManagerCommented:
Unfortunately it will only work on the active sheet, try this. It hides the selection process

Dim oWs As Worksheet

    Set oWs = ActiveSheet ''/// determine the current active sheet
    Application.DisplayAlerts = False
    Sheet1.Select
    ActiveWindow.DisplayGridlines = Not ActiveWindow.DisplayGridlines ''/// toggle gridlines
    oWs.Select
    Application.ScreenUpdating = True

Open in new window

0
 
sidwelleAuthor Commented:
'this works
ThisWorkbook.Windows(1).DisplayGridlines = True

'but whats the difference between a 'window' and a 'sheet' ?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
ThisWorkbook.Windows(1) will always refer to the active sheet so it is equivalent to ActiveWindow.
0
 
Roy CoxGroup Finance ManagerCommented:
Not sure where I found it but it's from my list useful tips that I have compiled over the years

ActiveWindow Property

Returns a Window object that represents the active window (the window on top). Read-only. Returns Nothing if there are no windows open.


ActiveSheet Property

Returns an object that represents the active sheet (the sheet on top) in the active workbook or in the specified window or workbook. Returns Nothing if no sheet is active. Read-only.

Remarks

If you don’t specify an object qualifier, this property returns the active sheet in the active workbook.
If a workbook appears in more than one window, the ActiveSheet property may be different in different windows.
0
 
sidwelleAuthor Commented:
Thank you,  I think I have enough to get it done.
0
 
Roy CoxGroup Finance ManagerCommented:
Pleased to help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now