Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Error '1004' - the specified value is out of range.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris - 28 Apr 2005 22:48 GMT
Could someone please enlighten me as to why I get a runtime error from this
line of code. It was generated by Excel 2003 itself using the 'record macro'
command from the 'tools menu'.  I selected 'record', then the rectangle shape
from the drawing tools menu, then dragged my cursor in the upper left corner
of my worksheet to the approx. size rectangle I wanted, then stopped
recording.  When I try to run the macro, I get "Runtime error '1004' - the
specified value is out of range."  I appreciate any response.

 I
Sub Macro1()
'
 ActiveSheet.Shapes.AddShape(msoShapeRectangle, 18#, 18#, 108#, 41.25). _
   Select
End Sub
Don Guillett - 28 Apr 2005 23:03 GMT
I just tested this in a regular module in xl2002 and it worked fine.

Signature

Don Guillett
SalesAid Software
donaldb@281.com

> Could someone please enlighten me as to why I get a runtime error from this
> line of code. It was generated by Excel 2003 itself using the 'record macro'
[quoted text clipped - 10 lines]
>     Select
> End Sub
Chris S. - 28 Apr 2005 23:32 GMT
Don, thanks for checking it out.  Did xl2002 generate the same line of code
during the record process?  This is absolutely maddening to me because I
can't get the macro to run for making rectangles or ovals in xl2003.  Are
there any xl2003 users out there who could try the record process.

> I just tested this in a regular module in xl2002 and it worked fine.
>
[quoted text clipped - 16 lines]
> >     Select
> > End Sub
Doug Glancy - 29 Apr 2005 00:54 GMT
Chris,

This is what I record in XL 03.  It works when I run it:

   ActiveSheet.Shapes.AddShape(msoShapeRectangle, 46.5, 43.5, 316.5, 240#).
_
       Select

I also ran your exact code and it worked.

Doug

> Don, thanks for checking it out.  Did xl2002 generate the same line of code
> during the record process?  This is absolutely maddening to me because I
[quoted text clipped - 21 lines]
> > >     Select
> > > End Sub
Chris S. - 29 Apr 2005 01:20 GMT
Doug, thanks for checkiing it in xl03.  After reading your results and
everyone elses, I went back and tried and failed again (something has to be
wrong).  Then I tried it in a new xl '03 workbook and it worked fine.  All I
can figure is that there was something incompatible in the workbook I was
originally trying it in.  It was an old workbook that had its origin in xl
'95 but had been saved to newer formats as my xl was upgraded.  It had been
working fine with other '03 features till this little quirk appeared.

Thanks to all.

> Chris,
>
[quoted text clipped - 37 lines]
> > > >     Select
> > > > End Sub
Tom Ogilvy - 29 Apr 2005 14:32 GMT
I can get that error if I don't have a valid constant value in the first
argument.  I would suggest you edited the macro and (inadvertently) changed
the first argument from something other than msoShapeRectangle  or you
redefined the value of msoShapeRectangle.

Signature

Regards,
Tom Ogilvy

> Doug, thanks for checkiing it in xl03.  After reading your results and
> everyone elses, I went back and tried and failed again (something has to be
[quoted text clipped - 47 lines]
> > > > >     Select
> > > > > End Sub
Don Guillett - 29 Apr 2005 13:33 GMT
I have xl95,xl97 and xl2002. So, I went to xl95 and created a workbook. I
then went to xl2002 and added the macro
sub dd
 ActiveSheet.Shapes.AddShape(msoShapeRectangle, 46.5, 43.5, 316.5,
240#).Select
end sub
and it worked fine in a regular module, in a sheet module and in
ThisWorkbook.
Corruption???

Signature

Don Guillett
SalesAid Software
donaldb@281.com

> Chris,
>
[quoted text clipped - 37 lines]
> > > >     Select
> > > > End Sub
Chris S. - 29 Apr 2005 16:36 GMT
This is baffling to me that I can't get it to work in my original workbook.  
Tom Ogilvy suggested that I may have inadvertently changed the constant
'msoShapeRectangle' , but that is not the case because I try running the
macro right after stopping the 'record macro' process and then get the
runtime error.  I get the same error when I record making an oval.

When I go through the same exact record process in a new xl 03 workbook, the
macros work fine.

When I compare the code from the two workbooks, it is absolutely identical.  

If I copy the working macro from the new workbook into my original, I get
the runtime error.  What gives?

Thanks for checking into it.  

> I have xl95,xl97 and xl2002. So, I went to xl95 and created a workbook. I
> then went to xl2002 and added the macro
[quoted text clipped - 53 lines]
> > > > >     Select
> > > > > End Sub
Chris S. - 29 Apr 2005 17:12 GMT
Here's a new twist.  When I copied the working macro from the vbmodule in the
new workbook to a module in my original, I get a runtime error which is
different.  Now it highlights 'msoShapeRectangle' and notes that 'variable is
undefined'.  There is something about my original workbook that it can't
recognize these 'msoShape' constants.

This is what I tried next.  With both workbooks open and a worksheet from my
problematic original workbook as the 'activesheet', I tried running the macro
using the macro command from the tools menu.  But this time I selected the
(identical) macro that was stored in the vb module in the new xl 03 workbook.
This time it worked fine, but  it won't work with the code stored in the
module in its own workbook.....

> This is baffling to me that I can't get it to work in my original workbook.  
> Tom Ogilvy suggested that I may have inadvertently changed the constant
[quoted text clipped - 69 lines]
> > > > > >     Select
> > > > > > End Sub
Tom Ogilvy - 29 Apr 2005 19:33 GMT
You need to go into tools=>References in the VBE and create a reference to
the office library.  That library is where the constant is defined.  Since
it appears you don't have a reference, the constant evaluated to Zero, the
same situation I hypothesized if the constant name was misspelled.

To see which reference, make your "new" workbook the activeproject and then
look in tools=>references.  You will see you have a reference to the office
type library there.  Make your "old" workbook have the same set of
references (the activeproject is the one that is selected in the project
window - when you do Tools=>References, you are looking at the reference
list for the activeproject).

Signature

Regards,
Tom Ogilvy

> Here's a new twist.  When I copied the working macro from the vbmodule in the
> new workbook to a module in my original, I get a runtime error which is
[quoted text clipped - 82 lines]
> > > > > > >     Select
> > > > > > > End Sub
Chris S. - 29 Apr 2005 22:38 GMT
Eureka Tom, you are the master!  That the constant, 'msoShapeRectangle',
wasn't being recognized had to mean that the library identifying that
constant wasn't being accessed.

When I did what you suggested in your post, I found that the 'MS Office 11
Object Library' was missing from the list in my old workbook.  I selected it
to add it to the reference list and then ran the macro.  It WORKED PERFECTLY!

Thank you for identifying the problem and working me through the fix....

> You need to go into tools=>References in the VBE and create a reference to
> the office library.  That library is where the constant is defined.  Since
[quoted text clipped - 113 lines]
> > > > > > > >     Select
> > > > > > > > End Sub
Jim Thomlinson - 28 Apr 2005 23:24 GMT
Works fine in xl2000

> Could someone please enlighten me as to why I get a runtime error from this
> line of code. It was generated by Excel 2003 itself using the 'record macro'
[quoted text clipped - 10 lines]
>     Select
> End Sub
JKing6000 - 15 Mar 2006 02:33 GMT
I've experienced the same difficulties and having followed the thead of
postings here, I have found them to be EXTEMELY helpful.  Thank you all for
your contributions!!

> Works fine in xl2000
>
[quoted text clipped - 12 lines]
> >     Select
> > End Sub
Andy Lock - 20 Sep 2006 11:04 GMT
This has just solved a problem that I have spent two solid days trying
to resolve.

Many thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.