+ Reply to Thread
Results 1 to 5 of 5

LateBinding and "Type not found"

Hybrid View

  1. #1
    Registered User
    Join Date
    12-04-2008
    Location
    The Mind
    Posts
    3

    Exclamation LateBinding and "Type not found"

    Can someone think along with me on this one? The module I am working on calls Excell from AutoCAD. Excel does a lot of things, then exports the result to a .txt file, wich is then used to make a drawing.

    A sub that I call (using late binding) is causing some problem I can't find a solution to. I should be able to dim a Range with a dimmed "excel.application" (xlapp = Excel.application). But it doesn 't work. I get a compile error: "user defined type not defined" when it runs into the latebound Range I dimmed.

    
        Dim LastrowB As Long
        Dim MyRange As xlapp. Range
        LastrowB = xlApp.Range("A" & Rows.count).End(xlUp).Row
        xlApp.Range("A1", "F" & LastrowB).Select
        
        For Each MyRange In xlApp.Selection
        MyRange.Value = Replace(MyRange.Value, ",", ".", , , vbTextCompare)
        Next
    I tried to get the program to recognise the "range" object like this:
    Dim rng As Object
    Set rng = CreateObject("Excel.Range")

    To no avail, the ActiveX couldn't create the object.
    Somehow I can't get it to recognise the Range when I put xlapp. in front of it.
    Without it, it works fine. But that will leave Excel running, wich is not an option.

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Hi

    You don't define Excel objects like that - I assume you have used CreateObject to create a late bound instance of an Excel.Application? Then you don't need to worry about the type of the range - just dim it as a variant. I'm not sure why you think Excel will remain open - the range does not exist separately to the application object - the moment you quit the application object of Excel, the range reference will be destroyed.

    Richard
    Richard Schollar
    Microsoft MVP - Excel

  3. #3
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284
    You don't need to create a range, you are just setting a variable referencing a range.

    If you are using late binding, then you cannot use the explicit datatype, you have to use the generic object

        Dim MyRange As Object

  4. #4
    Registered User
    Join Date
    12-04-2008
    Location
    The Mind
    Posts
    3
    Thanks for the pointers. I was looking in the wrong direction for too long. This was the solution to the problem:

     LastrowB = xlApp.Range  ("A" & xlApp.Application.Rows.count).End(xlUp).Row 
    Range was the problem, but the reason for that was caused elsewhere.
    Last edited by Hung; 12-04-2008 at 06:40 AM.

  5. #5
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284
    Quote Originally Posted by Hung View Post
    Thanks for the pointers. I was looking in the wrong direction for too long. This was the solution to the problem:

     LastrowB = xlApp.Range  ("A" & xlApp.Application.Rows.count).End(xlUp).Row 
    Range was the problem, but the reason for that was caused elsewhere.
    Surely, you don't need xlApp and Application, xlApp is the Application object.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1