Results 1 to 12 of 12

Thread: [RESOLVED] Application-defined or object defined error in Excel VBA from VB6

Threaded View

  1. #1

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

    Resolved [RESOLVED] Application-defined or object defined error in Excel VBA from VB6

    Note: Posting this thread for Hack
    I am getting an "Runtime error 1004 Application-defined or object defined error" on the highlighted line when I run this sub
    VB Code:
    1. Private Sub PrintIssues()
    2. Dim i As Long
    3.  
    4.     Set objExcel = New Excel.Application
    5.     Set bkWorkBook = objExcel.Workbooks.Add
    6.     Set shWorkSheet = bkWorkBook.ActiveSheet
    7.       If optAppeal.Value = True Then
    8.         shWorkSheet.Range("A1") = "Appeals Issues Log"
    9.       Else
    10.         shWorkSheet.Range("A1") = "Reopens Issues Log"
    11.       End If
    12.         shWorkSheet.Range("B3") = "Prov. Name:  " & strProvName
    13.         shWorkSheet.Range("A4") = "Prov. Number:  " & strProvCode
    14.        ' shWorkSheet.Range("C3") = "FYE:  " & cboFYE.Text
    15.       If optAppeal.Value = True Then
    16.         shWorkSheet.Range("A5") = "Appeal"
    17.       Else
    18.         shWorkSheet.Range("A5") = "Reopen"
    19.       End If
    20.         shWorkSheet.Range("C5") = "Number " & gstrAppealNo
    21.         shWorkSheet.Range("A8") = "Issue No"
    22.         shWorkSheet.Range("B8") = "Issue"
    23.         shWorkSheet.Range("C8") = "Analyst"
    24.         shWorkSheet.Range("D8") = "Disposition"
    25.         shWorkSheet.Range("E8") = "Est. Impact Amount"
    26.         shWorkSheet.Range("F8") = "Act. Impact Amount"
    27.         shWorkSheet.Range("G8") = "Comments"
    28.  
    29.     Set rngRowStart = shWorkSheet.Range("A10")
    30.          
    31.         bkWorkBook.Worksheets(1).Columns(1).HorizontalAlignment = xlLeft
    32.         bkWorkBook.Worksheets(1).PageSetup.Orientation = xlLandscape
    33.         bkWorkBook.Worksheets(1).PageSetup.Zoom = False
    34.         'in order for these PageSetup things to work, the ZOOM property
    35.         'must be set to false
    36.         bkWorkBook.Worksheets(1).PageSetup.FitToPagesWide = 1
    37.         bkWorkBook.Worksheets(1).PageSetup.FitToPagesTall = 1
    38.         bkWorkBook.Worksheets(1).Columns("E:E").HorizontalAlignment = xlCenter
    39.         bkWorkBook.Worksheets(1).Columns("F:F").HorizontalAlignment = xlCenter
    40.              
    41.             For i = 1 To lvwIssues.ListItems.Count
    42.                 'Place each element in the coresponding column
    43.                 rngRowStart.Offset(0, 0).Value = lvwIssues.ListItems(1).Text 'issue number
    44.                 rngRowStart.Offset(0, 1).Value = lvwIssues.ListItems(2).Text 'issue description
    45.                 rngRowStart.Offset(0, 2).Value = lvwIssues.ListItems(3).Text 'analyst
    46.                 rngRowStart.Offset(0, 3).Value = lvwIssues.ListItems(4).Text 'disposition
    47.                 rngRowStart.Offset(0, 4).Value = Format(lvwIssues.ListItems(5).Text, "###,#0") 'est impact amt
    48.                 rngRowStart.Offset(0, 5).Value = Format(lvwIssues.ListItems(6).Text, "###,#0") 'act impact amt
    49.                 rngRowStart.Offset(0, 6).Value = lvwIssues.ListItems(7).Text
    50.             Next
    51.                    
    52.             'Next Row
    53.             Set rngRowStart = rngRowStart.Offset(1, 0)
    54.        
    55.        'start with first row of recordset display and wedgie down a couple
    56.        lngLast = bkWorkBook.Worksheets(1).Range("A10").End(xlDown).Row + 2
    57.        [hl=yellow]bkWorkBook.Worksheets(1).Cells(lngLast, 5).Value = Format(lblEstImpAmt.Caption, "###,#0")[/hl] 'est impact total
    58.        bkWorkBook.Worksheets(1).Cells(lngLast, 6).Value = Format(lblActImpAmt.Caption, "###,#0") 'act impact total
    59.  
    60.         'make sure everything displays properly.
    61.         shWorkSheet.Columns("A:BZ").AutoFit
    62.        
    63.         objExcel.Visible = True
    64. End Sub
    Last edited by Hack; May 16th, 2006 at 08:48 AM. Reason: Added [RESOLVED] to thread title and green "resolved" checkmark
    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

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