Got error in Shapes.AddShape()

  • Thread starter Thread starter ramkumar_cpt
  • Start date Start date
R

ramkumar_cpt

Got error in this statement.

xlApp.Sheets(1).Shapes.AddShape(msoShapeRectangle, 60.75, 222.75, 6,
6).

Its working fine in Macro. I tried run this macro code using Visual
basic application. It is not working.

My vb code is..

Dim xlApp As Excel.Application '// Hold reference
to Excel Application
Dim xlWrkbk As Excel.Workbook '// Hold reference
to Full Template Excel
Dim objWorkSheet As Excel.Worksheet '// Hold reference
to Excel sheet

Private Sub Command1_Click()

'Initialize the Excel Application Properties
Set xlApp = New Excel.Application
xlApp.Visible = True


'// Open the Report Excel and the Full Template Excel
Set xlWrkbk = xlApp.Workbooks.Open("C:\ram.xls")
Set objWorkSheet = xlWrkbk.Worksheets("ProjectKPIs")

'// Display the link at start page
With xlApp.Sheets(1).Shapes.AddShape(msoShapeRectangle, 60.75,
222.75, 6, 6)
..Fill.ForeColor.SchemeColor = 18
End With

End Sub

Thanks in advance
Ram.
 
Hi,

You need to reference the workbook. Also the Fill command needs a
referencing dot added.

With xlWrkbk.Sheets(1).Shapes.AddShape( _
msoShapeRectangle, 60.75,222.75, 6, 6)
.Fill.ForeColor.SchemeColor = 18
End With

Cheers
Andy
 
Back
Top