+ Reply to Thread
Results 1 to 3 of 3

Typecasting Range from excel to work

  1. #1
    raven
    Guest

    Typecasting Range from excel to work

    Hi,

    Im basically try to read a part of a table from an excel file and inserting
    it as an OLE object in Work. The code seems to run fine when just 1 cell is
    selected, but throws a type mismatch error when the range containts multiple
    cells.



    My code is as follows(from word doc):

    Dim excel As Object
    Dim sheet As Object
    dim pRange as Range
    Set excel = CreateObject("Excel.Application")
    Set sheet = excel.ActiveSheet
    ' Works fine
    pRange = excel.Range(excel.Cells(1, 1), excel.Cells(1, 1))
    ' Throws type mismatch error
    pRange = excel.Range(excel.Cells(1, 1), excel.Cells(1, 2))
    pRange.InlineShapes.AddOLEObject , "c:\del.xls", , , , , , pRange

  2. #2
    Registered User
    Join Date
    08-11-2005
    Location
    Netherlands Waddinxveen
    Posts
    81
    Do not use excel as a variable name it's a reserved word in .......Excel!

  3. #3
    Dave Peterson
    Guest

    Re: Typecasting Range from excel to work

    Since pRange is an object variable:

    pRange = excel.Range(excel.Cells(1, 1), excel.Cells(1, 1))
    should be:
    SET pRange = excel.Range(excel.Cells(1, 1), excel.Cells(1, 1))

    or just
    SET pRange = excel.Range("a1")


    But I agree with Dnereb. I wouldn't use Excel or Sheet for my variable names.



    raven wrote:
    >
    > Hi,
    >
    > Im basically try to read a part of a table from an excel file and inserting
    > it as an OLE object in Work. The code seems to run fine when just 1 cell is
    > selected, but throws a type mismatch error when the range containts multiple
    > cells.
    >
    > My code is as follows(from word doc):
    >
    > Dim excel As Object
    > Dim sheet As Object
    > dim pRange as Range
    > Set excel = CreateObject("Excel.Application")
    > Set sheet = excel.ActiveSheet
    > ' Works fine
    > pRange = excel.Range(excel.Cells(1, 1), excel.Cells(1, 1))
    > ' Throws type mismatch error
    > pRange = excel.Range(excel.Cells(1, 1), excel.Cells(1, 2))
    > pRange.InlineShapes.AddOLEObject , "c:\del.xls", , , , , , pRange


    --

    Dave Peterson

+ 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