PDA

Click to See Complete Forum and Search --> : Problem in excel VBA coding **RESOLVED**


thiru_rajamani
Jan 19th, 2006, 10:56 PM
Hi all,
I did the following coding for retrieving some vaues from a excel sheet but I am facing problem in the red colour line "IsEmpty".

Run-Time error '1004':
Method 'Worksheets' of object '_Global' failed

I am doing this in VB 6.0 (Not in Excel)

Help please.
advance
Thanks

Raj



Sub RetValFrmxl(ChuckTyp As String, Ports As String)
Dim XlApp1 As Object
Dim XlApp As Object
Dim ExcelWasNotRunning As Boolean
Dim ActSht As Excel.Worksheet
Dim i, j, k As Long

Set XlApp1 = GetObject(App.Path & "\data.XLS")
XlApp1.Application.Visible = True
XlApp1.Parent.Windows(1).Visible = True
XlApp1.Worksheets(Ports).Activate

Set ActSht = XlApp1.ActiveSheet
i = 1
j = 0

Do While Not IsEmpty(Worksheets(Ports).Cells(i, 1))
If ActSht.Cells(i, 1).Value = "" Then
Exit Do
End If
If ActSht.Cells(i, 1).Value = ChuckTyp Then
For j = 2 To 8
If j = 2 Then
A = ActSht.Cells(i, j).Value
Debug.Print A
ElseIf j = 3 Then
B = ActSht.Cells(i, j).Value
Debug.Print B
ElseIf j = 4 Then
C = ActSht.Cells(i, j + 1).Value
Debug.Print C
ElseIf j = 5 Then
D = ActSht.Cells(i, j + 2).Value
Debug.Print D
ElseIf j = 6 Then
E = ActSht.Cells(i, j + 2).Value
Debug.Print E
ElseIf j = 7 Then
F = ActSht.Cells(i, j + 2).Value
Debug.Print F
ElseIf j = 8 Then
G = ActSht.Cells(i, j + 2).Value
Debug.Print G
End If
Next
End If
i = i + 1
Loop

If ExcelWasNotRunning = True Then
XlApp.Application.Quit
End If

Set XlApp = Nothing
End Sub

RobDog888
Jan 19th, 2006, 10:59 PM
Moved from Classic VB.

RobDog888
Jan 19th, 2006, 11:03 PM
This worked fine for me in a test book.
Dim Ports As String
Dim i As Integer
i = 1
Ports = "Sheet1"
Do While Not IsEmpty(Worksheets(Ports).Cells(i, 1))
MsgBox "Not empty"
Loop

thiru_rajamani
Jan 20th, 2006, 01:09 AM
This done the trick

Do While Not IsEmpty(ActSht.Cells(i, 1))