setting gridlines color without activating the worksheet

lalbatros

Well-known Member
Joined
Sep 5, 2007
Messages
659
Hello,

As a consequence of another thread, I have now this new question.
(see http://www.mrexcel.com/forum/showthread.php?p=1605723)

I would like to write a macro that sets the gridlines color of several worksheets.
But I don't want to activate each worksheet in a loop because of the visual impact.

It seem this is not possible since GridlineColorIndex is a property of a Window, not a property of a worksheet.
And to get a handle on a window, you need to activate a worksheet ...

Would there be a possibility anyway ?

thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
There is no need to activate a window to apply this property.

For instance you can just use:

Code:
Windows("Book2").GridlineColorIndex = 7

To change the gridline color and not activate the window.

Hope this helps.

Owen
 
Upvote 0
MorganO,

The problem arises when you have several worsheets in a workbook.
Say you have three worksheet in a workbook: Sheet1, Sheet2, and Sheet3.
Assume you want to write a macro to set the gridlines for Sheet1 and Sheet2.
Would that be possible without activating these two sheets?
In addition, in this statement:

Code:
Windows("Book2").GridlineColorIndex = 7

only the gridlines from the active sheet in book2 are changed.
The other sheets are unchanged.
 
Last edited:
Upvote 0
I realize that I misunderstood your question when I first read it, and yes you are correct, there doesn't seem to be a direct method to set the gridlinecolorindex without first activating a workbook then setting the index.

I thought that the following would possibly work:

Code:
Application.Workbooks("Book2").Worksheets("Sheet2").Application.Windows("Book2").GridlineColorIndex = 5

and although it executed with no error, it wouldn't change the colorindex unless the sheet2 is the currently active sheet.

I am assuming this must be doing this because of the design of the Excel Object Model.

I am sorry that I cannot assist further.

Can an MVP share any insight into this issue?

Owen
 
Upvote 0
I don't want to activate each worksheet in a loop because of the visual impact.
Do activate each worksheet if necessary, just use Application.ScreenUpdating = False before you start the loop.
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top