Executing Excel's Addshape Method thru VB

I have been handed a task to program an Excel spreadsheet using VB/VBA.  I have no exprience programming Excel and little exprience using Excel.  I have ordered two Excel books, but in the mean time I've been using the Excel help and VB Object browser to duplicate the sample spreadsheet using VB.  I am having problems adding shapes to my worksheet.  I am getting the following error when I use the Addshape Method:

Run-time error '1004': The specified value is out of range.

Here is my VB module code. What is wrong?

Private appExcel As Object
Private xlsWorkbooks As Object
Private myWorkbook As Object
Private myWorksheet As Object

Public Sub Main()
  Dim fName As String
 
  Set appExcel = CreateObject("Excel.Application")
  appExcel.Visible = False
  fName = appExcel.GetOpenFilename
 
  Set xlsWorkbooks = appExcel.Workbooks.Open(fName)
  Set myWorkbook = appExcel.Workbooks(1)
  Set myWorksheet = appExcel.Workbooks(1).Worksheets(1)
 
  myWorksheet.Range("A1").Select
  myWorksheet.Shapes.AddShape msoShapeRectangle, Selection.Left, Selection.Top, 10, 10
  'With myWorksheet.Shapes.AddShape(msoShapeRectangle, 50, 50, 100, 200)
   ' .Fill.ForeColor.RGB = RGB(100, 0, 0)
  'End With
  appExcel.Visible = True
  myWorkbook.Show
 
  xlsWorkbooks.Close False
  appExcel.Quit
End Sub
baileysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MTroutwineCommented:
You need to add a reference in your project to Microsoft Office 8.0 Object Library.  The shape object constants  (e.g. msoShapeRectangle) are found in that library not the Excel library.  

That should fix you up!

:>)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
baileysAuthor Commented:
Thanks, that worked!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.