PDA

View Full Version : how to open a sheet instead of another sheet?



maryam
03-06-2007, 04:53 AM
I have a subrutine for opening a sheet after another sheet. The code is :
SheetToOpen.Copy After:=origWkBk.Sheets(3).
how to open the sheet instead of another sheet?

Charlize
03-06-2007, 05:34 AM
Sub test()
Dim no As Long
no = ActiveSheet.Index
If no = Sheets.Count Then
MsgBox "Already last sheet selected"
Else
no = no + 1
Sheets(no).Select
End If
End Sub or do you want to open the previous sheetSheets(Worksheets.Count - 1).SelectCharlize

Bob Phillips
03-06-2007, 06:37 AM
Thisworkbook.activesheet.next.activate




Thisworkbook.activesheet.previous.activate

Norie
03-06-2007, 07:41 AM
What do you mean by 'open' a worksheet?

The code you posted copies a worksheet.

moa
03-06-2007, 09:08 AM
I think Maryam wants to know how to "open" the sheet before another sheet rather than after:

SheetToCopy.Copy Before:=origWkBk.Sheets(3)

maybe. :dunno

maryam
03-06-2007, 06:13 PM
I save some of the sheets of the current excel file in another excel file elsewhere before closing my file. then to open those sheets I use the following routin:

Private Sub CmdOpen_Click()
Dim oFileName As String
Dim wBook As Workbook
Dim SheetToOpen As Worksheet
Dim origWkBk As Workbook

' Allow user to select which workbook to open
oFileName = Application.GetOpenFilename(fileFilter:="Microsoft Office Excel Workbook (*.xls), *.xls", Title:="Select Workbook which contains the worksheet to open..")
If oFileName = "False" Then Exit Sub

'Open the first worksheet in the opened workbook
Application.ScreenUpdating = False
Set origWkBk = ActiveWorkbook
Workbooks.Open (oFileName)
Set wBook = Application.ActiveWorkbook
Set SheetToOpen = wBook.Sheets(1) 'Assuming the sheet we want to open is the always the first sheet
origWkBk.Activate
SheetToOpen.Copy After:=origWkBk.Sheets("menu") 'Open this worksheet after menu worksheet
'''''''''''''''''''''''''''''''''''''''''''''''''''
'To open a 2nd sheet
Set SheetToOpen = wBook.Sheets(2)
origWkBk.Activate
SheetToOpen.Copy After:=origWkBk.Sheets("Components") 'Open this worksheet after component worksheet
'''''''''''''''''''''''''''''''''''''''''''''''''''
wBook.Close
Application.ScreenUpdating = True
End Sub

This opens two sheets name menu2 and component2 after the menu and component sheet. Can we open these sheets instead of menu and component sheet?