Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Creating a rectangle on an Excel sheet from VB

I am trying to create a rectangle on an Excel sheet witht the
following code. It fails with: "the specified value is out of range"
I am running VB6 and Excel 2000 on a Windows XP pro PC.

Thanks, Yagil
===
Dim MyXl As Excel.Application

Sub main()
Dim uiSheet1 As Worksheet
Dim uiRectangle1 As Shape

Set MyXl = CreateObject("excel.application")
MyXl.Workbooks.Add
Set uiSheet1 = Sheets.Add


Set uiRectangle1 = uiSheet1.Shapes.AddShape(msoShapeRectangle, _
10, 10, 100, 100) 'error: the specified value is out of range

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating a rectangle on an Excel sheet from VB

Set uiRectangle1 = uiSheet1.Shapes.AddShape(1, _
10, 10, 100, 100) 'error: the specified value is out of range

Replace
msoShapeRectangle

with the value 1 since you apparently don't have a reference to the library
that defines msoShapeRectangle. (the office library)

--
Regards,
Tom Ogilvy




"JoeBen" wrote in message
...
I am trying to create a rectangle on an Excel sheet witht the
following code. It fails with: "the specified value is out of range"
I am running VB6 and Excel 2000 on a Windows XP pro PC.

Thanks, Yagil
===
Dim MyXl As Excel.Application

Sub main()
Dim uiSheet1 As Worksheet
Dim uiRectangle1 As Shape

Set MyXl = CreateObject("excel.application")
MyXl.Workbooks.Add
Set uiSheet1 = Sheets.Add


Set uiRectangle1 = uiSheet1.Shapes.AddShape(msoShapeRectangle, _
10, 10, 100, 100) 'error: the specified value is out of

range

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Creating a rectangle on an Excel sheet from VB

Thanks for the prompt answer.

I did have in my References: Microsoft Excel9.0 Object Library

When I now replaced msoShapeRectangle with 1, I get the error:
Type mismatch

"Tom Ogilvy" wrote:

Set uiRectangle1 = uiSheet1.Shapes.AddShape(1, _
10, 10, 100, 100) 'error: the specified value is out of range

Replace
msoShapeRectangle

with the value 1 since you apparently don't have a reference to the library
that defines msoShapeRectangle. (the office library)

--
Regards,
Tom Ogilvy




"JoeBen" wrote in message
...
I am trying to create a rectangle on an Excel sheet witht the
following code. It fails with: "the specified value is out of range"
I am running VB6 and Excel 2000 on a Windows XP pro PC.

Thanks, Yagil
===
Dim MyXl As Excel.Application

Sub main()
Dim uiSheet1 As Worksheet
Dim uiRectangle1 As Shape

Set MyXl = CreateObject("excel.application")
MyXl.Workbooks.Add
Set uiSheet1 = Sheets.Add


Set uiRectangle1 = uiSheet1.Shapes.AddShape(msoShapeRectangle, _
10, 10, 100, 100) 'error: the specified value is out of

range

End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Creating a rectangle on an Excel sheet from VB

I kept playing with the code, and (after adding the Office Library)
I got the following statement to work:

uiSheet1.Shapes.AddShape msoShapeRectangle, 10, 10, 100, 100

Since AddShape is supposed to return a Shape, I wonder why
setting uiRectangle1 caused an error.
By declaring uiRectangle1 as a Variant, I managed to run the statement:

Set uiRectangle1 = uiSheet1.Shapes.AddShape(msoShapeRectangle, 10, 10,
100, 100)

Go figure...

"JoeBen" wrote:

Thanks for the prompt answer.

I did have in my References: Microsoft Excel9.0 Object Library

When I now replaced msoShapeRectangle with 1, I get the error:
Type mismatch

"Tom Ogilvy" wrote:

Set uiRectangle1 = uiSheet1.Shapes.AddShape(1, _
10, 10, 100, 100) 'error: the specified value is out of range

Replace
msoShapeRectangle

with the value 1 since you apparently don't have a reference to the library
that defines msoShapeRectangle. (the office library)

--
Regards,
Tom Ogilvy




"JoeBen" wrote in message
...
I am trying to create a rectangle on an Excel sheet witht the
following code. It fails with: "the specified value is out of range"
I am running VB6 and Excel 2000 on a Windows XP pro PC.

Thanks, Yagil
===
Dim MyXl As Excel.Application

Sub main()
Dim uiSheet1 As Worksheet
Dim uiRectangle1 As Shape

Set MyXl = CreateObject("excel.application")
MyXl.Workbooks.Add
Set uiSheet1 = Sheets.Add


Set uiRectangle1 = uiSheet1.Shapes.AddShape(msoShapeRectangle, _
10, 10, 100, 100) 'error: the specified value is out of

range

End Sub





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating a rectangle on an Excel sheet from VB

Sub Tester1()
Dim uiSheet1 As Worksheet
Dim uiRectangle1 As Variant
Set uiSheet1 = ActiveSheet
Set uiRectangle1 = uiSheet1.Shapes.AddShape(1, _
10, 10, 100, 100)
Debug.Print TypeName(uiRectangle1)
End Sub


worked fine for me. ( returned Shape)

msoShapeRectangle isn't defined in the Excel object library. Notice I said
**Office** library.


Maybe you need to dimension uiRectangle1 as Excel.Shape. Does VB6 have a
"Shape" object?

--
Regards,
Tom Ogilvy


"JoeBen" wrote in message
...
Thanks for the prompt answer.

I did have in my References: Microsoft Excel9.0 Object Library

When I now replaced msoShapeRectangle with 1, I get the error:
Type mismatch

"Tom Ogilvy" wrote:

Set uiRectangle1 = uiSheet1.Shapes.AddShape(1, _
10, 10, 100, 100) 'error: the specified value is out of

range

Replace
msoShapeRectangle

with the value 1 since you apparently don't have a reference to the

library
that defines msoShapeRectangle. (the office library)

--
Regards,
Tom Ogilvy




"JoeBen" wrote in message
...
I am trying to create a rectangle on an Excel sheet witht the
following code. It fails with: "the specified value is out of range"
I am running VB6 and Excel 2000 on a Windows XP pro PC.

Thanks, Yagil
===
Dim MyXl As Excel.Application

Sub main()
Dim uiSheet1 As Worksheet
Dim uiRectangle1 As Shape

Set MyXl = CreateObject("excel.application")
MyXl.Workbooks.Add
Set uiSheet1 = Sheets.Add


Set uiRectangle1 = uiSheet1.Shapes.AddShape(msoShapeRectangle, _
10, 10, 100, 100) 'error: the specified value is out of

range

End Sub









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Creating a rectangle on an Excel sheet from VB

Using "Dim uiRectangle1 As excel.Shape" did the trick.

Thanks so much.


"Tom Ogilvy" wrote:

Sub Tester1()
Dim uiSheet1 As Worksheet
Dim uiRectangle1 As Variant
Set uiSheet1 = ActiveSheet
Set uiRectangle1 = uiSheet1.Shapes.AddShape(1, _
10, 10, 100, 100)
Debug.Print TypeName(uiRectangle1)
End Sub


worked fine for me. ( returned Shape)

msoShapeRectangle isn't defined in the Excel object library. Notice I said
**Office** library.


Maybe you need to dimension uiRectangle1 as Excel.Shape. Does VB6 have a
"Shape" object?

--
Regards,
Tom Ogilvy


"JoeBen" wrote in message
...
Thanks for the prompt answer.

I did have in my References: Microsoft Excel9.0 Object Library

When I now replaced msoShapeRectangle with 1, I get the error:
Type mismatch

"Tom Ogilvy" wrote:

Set uiRectangle1 = uiSheet1.Shapes.AddShape(1, _
10, 10, 100, 100) 'error: the specified value is out of

range

Replace
msoShapeRectangle

with the value 1 since you apparently don't have a reference to the

library
that defines msoShapeRectangle. (the office library)

--
Regards,
Tom Ogilvy




"JoeBen" wrote in message
...
I am trying to create a rectangle on an Excel sheet witht the
following code. It fails with: "the specified value is out of range"
I am running VB6 and Excel 2000 on a Windows XP pro PC.

Thanks, Yagil
===
Dim MyXl As Excel.Application

Sub main()
Dim uiSheet1 As Worksheet
Dim uiRectangle1 As Shape

Set MyXl = CreateObject("excel.application")
MyXl.Workbooks.Add
Set uiSheet1 = Sheets.Add


Set uiRectangle1 = uiSheet1.Shapes.AddShape(msoShapeRectangle, _
10, 10, 100, 100) 'error: the specified value is out of
range

End Sub








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
Excel 97 keeps changing dimensions of autoshape rectangle Roman Excel Discussion (Misc queries) 0 March 17th 10 04:38 PM
Excel - xy plot fill plotted rectangle Mark Charts and Charting in Excel 4 September 15th 09 04:54 PM
How do i delete a saved rectangle in excel? gltrg1991 Excel Worksheet Functions 3 February 17th 09 01:50 PM
How can cells be changed from rectangle to triangle in Excel? MD Excel Discussion (Misc queries) 1 February 21st 08 02:32 AM
Copy Rectangle Object From One Sheet To Another GeorgeF Excel Discussion (Misc queries) 0 May 24th 05 07:08 PM


All times are GMT +1. The time now is 02:57 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"