Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding worksheet grid lines in Excel?

Status
Not open for further replies.

AnotherJob

Programmer
Jun 13, 2007
25
0
0
US
I'm coding an Access DB that generates several Excel reports within a single workbook. The users want to have the grid line display turned off (displayed grid lines, not printed) on some of the worksheets.

Examples I've found use the ActiveWindow.DisplayGridLines method, but that will not work correctly since the workbook is generated as a background window (and must certainly not be forced into the foreground since that might disrupt concurrent tasks).

Is there a means of turning off the grid line display through worksheet properties directly? Or through some other means that doesn't demand the ActiveWindow? Thanks in advance.
 
YourWorkbookObject.Worksheets("yourSheetName").PageSetup.PrintGridlines = False

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
> YourWorkbookObject.Worksheets("yourSheetName").PageSetup.PrintGridlines = False

Thanks, but that is for the PRINTING of grid lines, not for their DISPLAY. The problem I refer to is related to Windows screen display of the Excel worksheets.
 



Tools > Options - View Tab: Window Options-GRIDLINES

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 



Also, it is a property of the WINDOW, which his a DISPLAY feature.

So prior to saving, make visible and assign this property.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
> So prior to saving, make visible and assign this property.

Thanks, but the "make visible" is the serious problem. Window manager actions are simply requests--they are not guarenteed to occur. A concurrent process could be hogging the Windows desktop, in which case the "make visible" request could halt all processing, which is not acceptable. And of course it would be poor programming anyway for a background reporting task to suddenly flash windows onto a screen, disrupting concurrent user interaction.

I feel there must be some way to access grid display as a property of the worksheet itself, which exists as a data object independently of the Windows desktop.
 
Nope - grid display is a property of the window, not of the worksheet

If you have all these concurrent processes happening, why are you faffing about with VBA. Go .NET and have proper control over the whole process. VBA is good but limited in terms of the control you have over the environment.

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
A workbook can have 'window' too, so (assuming it is displayed in one window):
YourWorkbookObject.Windows(1).DisplayGridlines = False

combo
 
> why are you faffing about with VBA. Go .NET and have proper control over the whole process.

If for a job, not a hobby project.
 
for a background reporting task
So, why bother DISPLAY issues ?
 
The code from my above post works for hidden/background window too. Have you tried it?

combo
 
Yes, before I posted my original question I did my research and testing. The code from your post just calls the ActiveWindow.DisplayGridLines method, (you can verify that with a macro recording), which only works correctly on worksheets that have been made the active window (using the Activate method beforehand).

The active window is the window that has current focus. If a user is typing in another window when Active is called, Active fails, and consequently the DisplayGridLines method also fails.
 
No, no ActiveWindow. ActiveWindow belongs to Application object and varies when one activates other workbook. YourWorkbookObject is hard reference to the worbook you work with.
I call the first window that belongs to given workbook. It can be inactive or hidden. A regular workbook in excel application always has one or more (rather rarely used)windows. It is possible to change differnt views in each and they will be stored.


combo
 
Try it! I cut and pasted your code directly when you first posted, and then I tested the results and confirmed that your code, unfortunately, acts upon the ActiveWindow object. You're simply accessing that window through a parent object. But if the window cannot be made active, due to preemptive concurrent use, then failure is assured.

Thanks for your suggestion, but I did test it and it does fail in concurrent use.
 
??? Can you post a selection of the code? What is the reference to the working workbook?

combo
 
You could always set cell borders to white - assuming users have a white background set.

Gavin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top