View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default is activating a hidden worksheet a no-no?

I created a two worksheet (sheet1 and sheet2) workbook. I hid sheet2 and then
ran this:

Worksheets("Sheet2").Activate
Debug.Print ActiveSheet.Name

I saw this in the immediate window:
Sheet1

I added this:

Worksheets("Sheet2").Activate
ActiveSheet.Range("A1").Value = 999

And the 999 was added to Sheet1. I unhid sheet2 and A1 was empty.

I wouldn't activate a hidden sheet and expect it to work the way I want.

But there are not many things that you do in code that needs to work on the
activesheet. Maybe just working on the sheet directly would be sufficient in
your case:

with worksheets("Sheet2") 'still hidden
.range("a1").value = "some value"
end with



Brian Murphy wrote:

Hello everyone,

I have a VBA routine in an addin that .Activates a hidden worksheet in
the user's workbook.

Is this an unwise thing to do?

Thanks,

Brian


--

Dave Peterson