Problem with "Application.Goto Reference" code line

R

Robert Crandal

In my Workbook_Open() subroutine, I run the following line of code:

Application.Goto Reference:=Sheets("Sheet1").Range("A1"), scroll:=True

This code works okay, but whenever I mark my "Sheet1" as hidden, the
code no longer works. The error message that I get is Run-Time
Error 1004 - Method 'Goto' of Object '_Application' Failed.

Is there any way to use that line of code on a hidden sheet??

thanx
 
D

Dave Peterson

Dim myCell as range
set mycell = worksheets("sheet1").range("A1")

mycell.parent.visible = xlsheetvisible
application.goto reference:=mycell, scroll:=true

Just unhide the sheet yourself. If the sheet is already visible, then the
..visible line won't cause trouble.
(If the workbook's structure is protected, you will get an error, though.)
 
R

Robert Crandal

So, to set the sheet as hidden again, would I use the following
line:

mycell.parent.visible = xlSheetHidden ' ???
 
D

Dave Peterson

Sounds like it's worth testing!

Robert said:
So, to set the sheet as hidden again, would I use the following
line:

mycell.parent.visible = xlSheetHidden ' ???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top