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

open a specific Excel worksheet

Status
Not open for further replies.

testeng

Technical User
Apr 5, 2001
32
US
Hi,
I know how to open up excel through VB but I can't make it open up a specific worksheet. Does anybody know how to make it open up a specific workbook then goto a specific worksheet.

thanks for your help
 
use vindex=# if you know the sheet number
use vindex="Abc" if you know the sheet name


[tt]
Option Explicit

Private Sub Command1_Click()
Dim oXL
Dim oWB
Dim oSheet
Dim vIndex As Variant
Dim sFile As String

sFile = "D:\MSDN\2000JAN\1033\SAMPLES\VB98\Geofacts\WORLD.XLS"
vIndex = 3
vIndex = "Antartica"


Set oXL = CreateObject("Excel.Application")
Set oWB = oXL.Workbooks.Open(sFile)
Set oSheet = oWB.Worksheets(vIndex)
oXL.Visible = True
oSheet.Activate
MsgBox "Worksheet " & vIndex & " of " & sFile & " activated"
Set oSheet = Nothing
oWB.Saved = True
oWB.Close
Set oWB = Nothing
oXL.Quit
Set oXL = Nothing
End Sub
[/tt]
 
If after You activate the sheet and it's not active, activate an other sheet and reactivate the wanted sheet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top