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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
I just tested this in a regular module in xl2002 and it worked fine.
 
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.
 
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
 
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.
 
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???
 
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.
 
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.
 
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.....
 
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).
 
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....
 
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!!
 
This has just solved a problem that I have spent two solid days trying
to resolve.

Many thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top