I’ve been looking for the answer to this problem for around 2 hours while working on other code. It seems like my answer should be listed in the MSDN because of its simplicity but I cant find it anywhere.

And my problem is thus: I have this VB6 program that opens up and messes with some values in an excel spreadsheet and when its done has to go to the next Sheet in the workbook (Sheet2) and do it all over again….. But I don’t know how to change its focus to Sheet2 so it can access the cells in that sheet! >.<

Using this dummy connection code what would I add to it to get it to select and show Sheet2 in the workbook?

Thanks in advance, I know my question is kinda silly. ^^;

Option Explicit
     
    Private Sub Form_Load()
      Dim AppExcel As Excel.Application
      Dim wBook As Workbook
      Dim mySheet As Worksheet
     
      Set AppExcel = New Excel.Application
      AppExcel.Application.Visible = True
      AppExcel.Workbooks.Add 'Adds a new book.
     
     
    End Sub

Recommended Answers

All 4 Replies

Boy do I feel foolish.

Sheets("Name of sheet").Select
Sheets(index).Select

Dont code while tired kids, makes you do some crazy things.

I want to know too,
Because, in my Web, Usr can upload the Excel file to write the data to Access, but now, i must confine the sheet name, just that my Programe only read sheet name a time~~~

'----------------------------------------------------------------
Set conn =server.CreateObject("ADODB.Connection") dbPath=server.MapPath(fileNa) conn.Open "driver={Microsoft Excel Driver (*.xls)};dbq=" & dbPath
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "[random$]", conn, adOpenStatic 
'-----------------------------

how to do, so i can read sheet name many time, or i can choose the sheet name;)

Boy do I feel foolish.

Sheets("Name of sheet").Select
Sheets(index).Select

Dont code while tired kids, makes you do some crazy things.

That's how you change the active sheet.

myWkBook.Sheets("Sheet1").Activate

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.