View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
deko[_2_] deko[_2_] is offline
external usenet poster
 
Posts: 53
Default How to embed chart in active worksheet with VBA?

As far as I can tell, this *should* embed my chart in the Active worksheet:

xlapp.Workbooks(strXlsFile).ActiveChart.Location Whe= _
xlLocationAsObject, Name:=strSheetName

(where strSheetName is the name of the target worksheet)

But when I put this code in a loop, the chart is created in it's *own
sheet*:

xlapp.Workbooks(strXlsFile).Charts.Add.Name = strSheetName
xlapp.Workbooks(strXlsFile).ActiveChart.SetSourceD ata Source:= _
xlapp.Workbooks(strXlsFile).Worksheets(j + 1).Range("A1:C" & _
xlapp.Workbooks(strXlsFile).Worksheets(j + 1).Range("C1").End(xlDown).Row),
PlotBy:=xlColumns
xlapp.Workbooks(strXlsFile).ActiveChart.Axes(xlCat egory, xlPrimary).HasTitle
= False
xlapp.Workbooks(strXlsFile).ActiveChart.Axes(xlVal ue, xlPrimary).HasTitle =
False
xlapp.Workbooks(strXlsFile).ActiveChart.HasLegend = False
xlapp.Workbooks(strXlsFile).ActiveChart.HasTitle = False

Am I missing something obvious, or do I need to do something different when
using automation?

Thanks in advance.