Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Typecasting Range from excel to work


Do not use excel as a variable name it's a reserved word in
........Excel!


--
Dnereb
------------------------------------------------------------------------
Dnereb's Profile: http://www.excelforum.com/member.php...o&userid=26182
View this thread: http://www.excelforum.com/showthread...hreadid=397028

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
flash object dont work in my excel work sheet Nitn Excel Discussion (Misc queries) 0 July 4th 09 08:00 AM
Formulas assignment from array to range in VSTO Excel doesn't work vsto excel array to range Excel Worksheet Functions 0 December 11th 07 04:48 PM
Why doesn't this range work? Pete K Excel Programming 4 April 10th 04 04:06 AM
Excel Macro Problem, Add-in need to work in every workbook & Error:9 Subscript out of range Burak[_2_] Excel Programming 1 October 31st 03 08:09 PM
HELP!! Range selection doesn't work pingger Excel Programming 0 July 28th 03 09:24 PM


All times are GMT +1. The time now is 07:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"