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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excell Syntax?? 1

Status
Not open for further replies.
May 2, 2003
175
GB
Hi there, I can't seem to get the syntax of:

Sheets("Sheet1").Select

To work, what is wrong with this and why does it keep stopping my macro?
All I am trying to do is select the first sheet of a workbook in excel.

I have tried the above, with and without quote marks, and with and without a capital letter on "sheet1" yet nothing works, is there a way of selecting just the first sheet in any workbook?

Any help would be most apreciated.

When student asks a questions, often the most obvious solution is the answer.
 
Ok, I have found the problem, what it is is that I am trying to make it so when a workbook opens, it will select only the first sheet.

Is it possible to do this, eg
save one spreadsheet,
close it
open the dialog box (to pick another spreadsheet)
and then have it select just the first sheet on opening?

When student asks a questions, often the most obvious solution is the answer.
 
Assuming there is a sheet called "Sheet1" in the new workbook,
Sheets("Sheet1").Select
should do it! Otherwise, the new workbook will open on the page it was closed from so if applicable you could close from Sheet1.?
 
Hi,

Check out Bowers74 faq707-4090 Refer to Worksheets more effecively in a Procedure

You can use the WorkBook_Open event and use the Activate method on any sheet you desire.

:)

Skip,
Skip@TheOfficeExperts.com
 
I have tried this, and it does not like it, I get a runtime error 9.

this is the basic code

ActiveWorkbook.Save
ActiveWindow.Close
Application.Dialogs(xlDialogOpen).Show
Sheets("Sheet1").Select

Should there be some line in there indicating to wait for user input or something like that?

When student asks a questions, often the most obvious solution is the answer.
 
...it will select only the first sheet...

To select the first sheet regardless of name:
[blue]
Code:
  Sheets(1).Activate
[/color]

And if you want to do that automatically when the workbook is opened, put code on the Workbook code page to process the Workbook_Open event:
[blue]
Code:
  Private Sub Workbook_Open()
    Sheets(1).Activate
  End Sub
[/color]

 
Absolutely spot on Zathras, thanks for your help. The problem was actually with the bracketed words ("Sheet1") when (1) is quite sufficient.


When student asks a questions, often the most obvious solution is the answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top