CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    [RESOLVED] Some Explanation about Difference Between New and Createobject

    Can anybody tell me .Why i am getting Error ActiveX Component Cannot CreateObject.here is the following Code.
    Code:
    Private Sub btPrint_Click()
    Dim excl As Excel.Application
    Dim wBook As Excel.Workbook
    Dim ExlSheet As Excel.Worksheet
    Dim m_SCompanyName As String
     m_SCompanyName = "AL ARABI FACTORY FOR STEEL WORKS      "
                    
    
      ' Set excl = New Excel.Application
      Set excl = CreateObject(Excel.Application)
      Set wBook = excl.Workbooks.Add
      Set ExlSheet = wBook.Worksheets(1)
             excl.Visible = True
             ExlSheet.Cells(2, 1).Value = m_SCompanyName
             ExlSheet.Cells(3, 1).Value = "P.O. BOX 14044 DAMMAM 31424  "
             ExlSheet.Cells(4, 1).Value = "KINGDOM OF SAUDI ARABIA      "
             ExlSheet.Cells(5, 1).Value = "PHONE :  (+9663) 812-3070    "
             ExlSheet.Cells(6, 1).Value = "FAX     :   (+9663) 812-3339 "
             ExlSheet.Range("A1:A2").Font.Bold = True
             ExlSheet.Range("A1:A2").Font.Italic = True
             ExlSheet.Range("A1:A5").Font.Underline = True
            ' ActiveSheet.Pictures.Insert (App.path & "FirmSignation.jpg"), Range("B5:D10")
           '  Call PlacePicture
           wBook.SaveAs App.path & "PurchaseOrder.Xls"
          ' wBook.Close savechanges:=True
              Set ExlSheet = Nothing
              Set wBook = Nothing
           '   excl.Quit
              Set excl = Nothing
    End Sub
    But when i write a code Set excl = CreateObject(Excel.Application) instead of Set Set excl = New Excel.Application. i got error ActiveX Component Cannot Create Object
    i got error ACtiveX Component Cannot create Object .Kindly let me know the Idea.if Possible Kindly Explain .These two Specific Line.
    Code:
     'Set excl = New Excel.Application
      Set excl = CreateObject(Excel.Application)
    Last edited by firoz.raj; November 10th, 2009 at 07:32 AM.

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

Featured