• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

DisplayGridlines property

DJ

Member
Hi,


I have a query regarding a VBA code that is ActiveWindow.DisplayGridlines = True/False.


Why do I need to refer to the active window in the above mentioned code line? If I give a reference to a worksheet that is not active it doesn't work e.g. if write Sheets("Sheet1").DisplayGridlines=False, it doesn't work and give me an error "Run-time error '438': Object doesn't support this property or method".


Kindly help me know the logic behind this.


Thanks and regards,

DJ
 
Hi, DJ!


For the same reason that you have to press Alt-F11 to enter in VBA editor: because the guy who programmed that feature decided it so. In the case of the DisplayGridlines property as you can check in the built-in help because it's required to be applied to an expression which represent a Window object.


Regards!
 
Hi SirJB7,


So every time when I need display or remove gridlines of a worksheet, in my code I need to first activate it?


Thanks and regards,

DJ
 
DJ


Gridlines are a window property and are set at the same location as the cells on display in the active window


Cell Borders are a Range property and can be set by referencing the worksheet/range accordingly
 
Hi, DJ!

Actually I rarely use Window object, but I think that if you activate the related sheet first everything will be ok, if not you'd have to qualificate the Window object -that I didn't do it never- or use Windows(n), where "n" is the windows number of current workbook (n=1 for active window).

Regards!
 
Hi, DJ!

Actually I rarely use Window object, but I think that if you activate the related sheet first everything will be ok, if not you'd have to qualificate the Window object -that I didn't do it never- or use Windows(n), where "n" is the windows number of current workbook (n=1 for active window).

Regards!
 
Back
Top