Results 1 to 4 of 4

Thread: Problem in excel VBA coding **RESOLVED**

  1. #1

    Thread Starter
    Addicted Member thiru_rajamani's Avatar
    Join Date
    Aug 2004
    Location
    Chennai,India
    Posts
    214

    Resolved Problem in excel VBA coding **RESOLVED**

    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



    VB Code:
    1. [FONT=Courier New]Sub RetValFrmxl(ChuckTyp As String, Ports As String)
    2. Dim XlApp1 As Object
    3. Dim XlApp As Object
    4. Dim ExcelWasNotRunning As Boolean
    5. Dim ActSht As Excel.Worksheet
    6. Dim i, j, k As Long
    7.  
    8.     Set XlApp1 = GetObject(App.Path & "\data.XLS")
    9.     XlApp1.Application.Visible = True
    10.     XlApp1.Parent.Windows(1).Visible = True
    11.     XlApp1.Worksheets(Ports).Activate
    12.    
    13.     Set ActSht = XlApp1.ActiveSheet
    14.     i = 1
    15.     j = 0
    16.  
    17.    [COLOR=Sienna]     Do While Not IsEmpty(Worksheets(Ports).Cells(i, 1))[/COLOR]            
    18. If ActSht.Cells(i, 1).Value = "" Then
    19.                 Exit Do
    20.             End If
    21.             If ActSht.Cells(i, 1).Value = ChuckTyp Then
    22.                 For j = 2 To 8
    23.                     If j = 2 Then
    24.                         A = ActSht.Cells(i, j).Value
    25.                         Debug.Print A
    26.                     ElseIf j = 3 Then
    27.                         B = ActSht.Cells(i, j).Value
    28.                         Debug.Print B
    29.                     ElseIf j = 4 Then
    30.                         C = ActSht.Cells(i, j + 1).Value
    31.                         Debug.Print C
    32.                     ElseIf j = 5 Then
    33.                         D = ActSht.Cells(i, j + 2).Value
    34.                         Debug.Print D
    35.                     ElseIf j = 6 Then
    36.                         E = ActSht.Cells(i, j + 2).Value
    37.                         Debug.Print E
    38.                     ElseIf j = 7 Then
    39.                         F = ActSht.Cells(i, j + 2).Value
    40.                         Debug.Print F
    41.                     ElseIf j = 8 Then
    42.                         G = ActSht.Cells(i, j + 2).Value
    43.                         Debug.Print G
    44.                     End If
    45.                 Next
    46.             End If
    47.         i = i + 1
    48.         Loop
    49.  
    50.    If ExcelWasNotRunning = True Then
    51.       XlApp.Application.Quit
    52.    End If
    53.  
    54.    Set XlApp = Nothing
    55. End Sub[/FONT]
    Last edited by thiru_rajamani; Jan 20th, 2006 at 02:09 AM.
    Thanks
    Raj

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Problem in excel VBA coding

    Moved from Classic VB.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Problem in excel VBA coding

    This worked fine for me in a test book.
    VB Code:
    1. Dim Ports As String
    2.     Dim i As Integer
    3.     i = 1
    4.     Ports = "Sheet1"
    5.     Do While Not IsEmpty(Worksheets(Ports).Cells(i, 1))
    6.         MsgBox "Not empty"
    7.     Loop
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Addicted Member thiru_rajamani's Avatar
    Join Date
    Aug 2004
    Location
    Chennai,India
    Posts
    214

    Talking Re: Problem in excel VBA coding

    This done the trick

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width