![]() |
visible method of worksheet class failed error
This works for me:
ActiveWorkbook.Unprotect Password:="pw" Sheets("Main").Unprotect Password:="pw" Sheets("Main").Visible = True Sheets("Main").Activate Range("D2").Select Sheets("costsheet").Visible = False Sheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" I don't see why you had the "Dim Main as Worksheets" declaration, and I don't think you need it. Hope this helps, Hutch "bigjim" wrote: I am running exel 2003 and get a run-time error '1004 Visible method of worksheet class failed. I am simply trying to go from one sheet that is visible now <costsheet to another sheet <Main that is not visible now. When I get to <main, I then want to hide <costsheet I have tried all the tricks I know of to no avail and could use a little help. Here is my code: ActiveWorkbook.Unprotect Password:="pw" Dim Main As Worksheets Worksheets("Main").Unprotect Password:="pw" Worksheets("Main").Visible True <This is where it bogs down Worksheets("Main").Range("d2").Select Worksheets("costsheet").Visible False Worksheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" End Sub |
visible method of worksheet class failed error
Well, it got me on line further. Now at the line <Range("D2").Select it
shuts down with a "Select method of range class failed" errror. Anything else you can think of? Jim "Tom Hutchins" wrote: This works for me: ActiveWorkbook.Unprotect Password:="pw" Sheets("Main").Unprotect Password:="pw" Sheets("Main").Visible = True Sheets("Main").Activate Range("D2").Select Sheets("costsheet").Visible = False Sheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" I don't see why you had the "Dim Main as Worksheets" declaration, and I don't think you need it. Hope this helps, Hutch "bigjim" wrote: I am running exel 2003 and get a run-time error '1004 Visible method of worksheet class failed. I am simply trying to go from one sheet that is visible now <costsheet to another sheet <Main that is not visible now. When I get to <main, I then want to hide <costsheet I have tried all the tricks I know of to no avail and could use a little help. Here is my code: ActiveWorkbook.Unprotect Password:="pw" Dim Main As Worksheets Worksheets("Main").Unprotect Password:="pw" Worksheets("Main").Visible True <This is where it bogs down Worksheets("Main").Range("d2").Select Worksheets("costsheet").Visible False Worksheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" End Sub |
visible method of worksheet class failed error
Yes. I ran this code from a general VBA module and it worked perfectly. I'm
guessing you have your code in a sheet module. When code is in a general module, an unqualified range will refer to the active sheet. But in a sheet module (code that is behind a worksheet), an unqualified range will refer to that sheet. You can only select a range on a sheet that is active. Change Sheets("Main").Activate Range("D2").Select to Sheets("Main").Activate ActiveSheet.Range("D2").Select Hope this helps, Hutch "bigjim" wrote: Well, it got me on line further. Now at the line <Range("D2").Select it shuts down with a "Select method of range class failed" errror. Anything else you can think of? Jim "Tom Hutchins" wrote: This works for me: ActiveWorkbook.Unprotect Password:="pw" Sheets("Main").Unprotect Password:="pw" Sheets("Main").Visible = True Sheets("Main").Activate Range("D2").Select Sheets("costsheet").Visible = False Sheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" I don't see why you had the "Dim Main as Worksheets" declaration, and I don't think you need it. Hope this helps, Hutch "bigjim" wrote: I am running exel 2003 and get a run-time error '1004 Visible method of worksheet class failed. I am simply trying to go from one sheet that is visible now <costsheet to another sheet <Main that is not visible now. When I get to <main, I then want to hide <costsheet I have tried all the tricks I know of to no avail and could use a little help. Here is my code: ActiveWorkbook.Unprotect Password:="pw" Dim Main As Worksheets Worksheets("Main").Unprotect Password:="pw" Worksheets("Main").Visible True <This is where it bogs down Worksheets("Main").Range("d2").Select Worksheets("costsheet").Visible False Worksheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" End Sub |
visible method of worksheet class failed error
That did it. Thank you so much. Not only did you solve this issue, you
taught me a little bit about what was going on, which will help in the future. I really appreciate the help. Jim "Tom Hutchins" wrote: Yes. I ran this code from a general VBA module and it worked perfectly. I'm guessing you have your code in a sheet module. When code is in a general module, an unqualified range will refer to the active sheet. But in a sheet module (code that is behind a worksheet), an unqualified range will refer to that sheet. You can only select a range on a sheet that is active. Change Sheets("Main").Activate Range("D2").Select to Sheets("Main").Activate ActiveSheet.Range("D2").Select Hope this helps, Hutch "bigjim" wrote: Well, it got me on line further. Now at the line <Range("D2").Select it shuts down with a "Select method of range class failed" errror. Anything else you can think of? Jim "Tom Hutchins" wrote: This works for me: ActiveWorkbook.Unprotect Password:="pw" Sheets("Main").Unprotect Password:="pw" Sheets("Main").Visible = True Sheets("Main").Activate Range("D2").Select Sheets("costsheet").Visible = False Sheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" I don't see why you had the "Dim Main as Worksheets" declaration, and I don't think you need it. Hope this helps, Hutch "bigjim" wrote: I am running exel 2003 and get a run-time error '1004 Visible method of worksheet class failed. I am simply trying to go from one sheet that is visible now <costsheet to another sheet <Main that is not visible now. When I get to <main, I then want to hide <costsheet I have tried all the tricks I know of to no avail and could use a little help. Here is my code: ActiveWorkbook.Unprotect Password:="pw" Dim Main As Worksheets Worksheets("Main").Unprotect Password:="pw" Worksheets("Main").Visible True <This is where it bogs down Worksheets("Main").Range("d2").Select Worksheets("costsheet").Visible False Worksheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" End Sub |
visible method of worksheet class failed error
Try:
Sheets("Main").Range("D2").Select bigjim wrote: Well, it got me on line further. Now at the line <Range("D2").Select it shuts down with a "Select method of range class failed" errror. Anything else you can think of? Jim "Tom Hutchins" wrote: This works for me: ActiveWorkbook.Unprotect Password:="pw" Sheets("Main").Unprotect Password:="pw" Sheets("Main").Visible = True Sheets("Main").Activate Range("D2").Select Sheets("costsheet").Visible = False Sheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" I don't see why you had the "Dim Main as Worksheets" declaration, and I don't think you need it. Hope this helps, Hutch "bigjim" wrote: I am running exel 2003 and get a run-time error '1004 Visible method of worksheet class failed. I am simply trying to go from one sheet that is visible now <costsheet to another sheet <Main that is not visible now. When I get to <main, I then want to hide <costsheet I have tried all the tricks I know of to no avail and could use a little help. Here is my code: ActiveWorkbook.Unprotect Password:="pw" Dim Main As Worksheets Worksheets("Main").Unprotect Password:="pw" Worksheets("Main").Visible True <This is where it bogs down Worksheets("Main").Range("d2").Select Worksheets("costsheet").Visible False Worksheets("Main").Protect Password:="pw" ActiveWorkbook.Protect Password:="pw" End Sub -- Dave Peterson |
All times are GMT +1. The time now is 02:44 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com