VB6 - Run-Time error 1004 Unable to get the add property of the sheets class
Gentlemen,
I wanna kill two birds with one stone here, I hope you won't mind
Problem#1:
I am getting a "runtime error 1004 - Unable to get the Add property of the sheets class" on this line of code:
Dim NewxlWksht As object
Set NewxlWksht = xlWbk.Worksheets.Add("Sheet2").
Problem#2:
I am also getting "Runtime error 438 - Object does not support this property or method" on this line of code:
Dim WkshtName As String
WkshtName = xlWksht.Sheets(1).Name
What am I doing wrong?
Thanks.
GiftX
[570 byte] By [
Giftx] at [2007-11-20 11:32:36]

# 1 Re: VB6 - Run-Time error 1004 Unable to get the add property of the sheets class
Look at this:
Option Explicit
' Add a reference to Excel Object Library x.x
Private Sub Form_Load()
Call SheetExists("test.xls")
End Sub
Sub SheetExists(nameX As String)
Dim xls As New Excel.Application
Dim wk As New Excel.Workbook
Dim i As Integer
Set wk = xls.Workbooks.Open(App.Path & "\test.xls")
With wk.Worksheets
For i = 1 To .Count
If .Item(i).Name = nameX Then
MsgBox "Found"
Exit For
End If
Next
End With
Set wk = Nothing
xls.Quit
Set xls = Nothing
End Sub