Results 1 to 7 of 7

Thread: Cannot create ActiveX component.

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    6

    Cannot create ActiveX component.

    This is an issue where when the code hits ExcelObj = CreateObject("Excel.Application") line it throws the "Cannot create ActiveX component" error. Does anyone know why this is happening?





    Sub SavePartNumbersInSession()
    Dim ExcelObj As Object
    'Dim ExcelBook As Object
    'Dim ExcelSheet As Object
    Dim i As Integer
    Dim j As Integer
    'Dim cells As Object

    ExcelObj = CreateObject("Excel.Application")
    'ExcelSheet = CreateObject("Excel.Sheet")

    ExcelObj.WorkBooks.Open(sPath & "UploadedFiles\" & System.IO.Path.GetFileName(MyFile.PostedFile.FileName))

    'ExcelBook = ExcelObj.Workbooks(1)
    'ExcelSheet = ExcelBook.WorkSheets(1)

    i = 1
    j = 2

    'cells = ExcelBook.WorkSheets(1).cells

    Session("PartNumbers") = ""

    Do Until ExcelObj.Workbooks(1).WorkSheets(1).cells(1, i).value & "" = ""

    If ExcelObj.Workbooks(1).WorkSheets(1).cells(1, i).value = "Part Number" Then
    ExcelObj.Workbooks(1).WorkSheets(1).UsedRange.Columns(i).NumberFormat = "@"

    Do Until ExcelObj.Workbooks(1).WorkSheets(1).cells(j, i).value & "" = ""
    'If IsNumeric(ExcelObj.Workbooks(1).WorkSheets(1).cells(j, i).value) Then
    If Session("PartNumbers") <> "" Then
    Session("PartNumbers") &= "|"
    End If

    Session("PartNumbers") &= CStr(ExcelObj.Workbooks(1).WorkSheets(1).cells(j, i).value)
    ' End If


    j = j + 1
    Loop
    End If

    i = i + 1
    Loop

    ExcelObj.DisplayAlerts = False
    ExcelObj.Workbooks(1).Close()
    ExcelObj.Quit()

    ExcelObj = Nothing
    End Sub

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,904

    Re: Cannot create ActiveX component.

    This is VB.Net code, not VB6 or earlier

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Cannot create ActiveX component.

    At this link, CreateObject in .Net is described, along with a simple example of using it to automate Excel
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Cannot create ActiveX component.

    Maybe add a 'Set' infront?

  5. #5
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Cannot create ActiveX component.

    No need for multiple threads we will help when we can.
    http://www.vbforums.com/showthread.p...won-t-turn-off

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: Cannot create ActiveX component.

    Quote Originally Posted by Max187Boucher View Post
    Maybe add a 'Set' infront?
    You don't use Set in .Net. You can assign objects to object variables the same way you assign values to primitive types.

    Maybe a mod should move this thread.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  7. #7
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,902

    Re: Cannot create ActiveX component.

    ...and maybe a mod has
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

Tags for this Thread

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