Got error in Shapes.AddShape()

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.
 
A

Andy Pope

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
 

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

Top