View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JeroenM JeroenM is offline
external usenet poster
 
Posts: 5
Default It works .... but only 1 time

Hello,

From access I want to export a query to Excel (wit the help of som e VBA
code). I do this because I want to make a proper graph (among some other
things). Because the number of columns can change (so the number of series in
my chart) I want to use a piece of VBA code to expand my graph as needed.
This piece of VBA code looks if there is a column left, if yes I add it to
the graph as a new series.

I recorded a macro in Excel and got the following piece of VBA code for
adding the column to the graph:
================================================== ===
xlAppForm.Worksheets(WorksheetName ).Range(ActiveSheet.Cells(16, 14 + Sprong
*
T2), ActiveSheet.Cells(27, (14 + Sprong * T2))).Select
xlAppForm.Selection.Copy

xlAppForm.ActiveSheet.ChartObjects("Grafiek 2").Activate
xlAppForm.ActiveChart.ChartArea.Select

xlAppForm.ActiveChart.SeriesCollection.Paste Rowcol:=xlColumns,
SeriesLabels:=False, CategoryLabels:=False, Replace:=False, NewSeries:=True
xlAppForm.ActiveChart.SeriesCollection(T2 + 1).Name = xlAppQuery.Cells(T1, 2)
================================================== ===

The VBA code above works fine, but ....... it works only 1 time. The second
time (after I run the programm again) no series/columns are added to the
graph. Do i close access (where the VBA code is located) and start the
programm again, it works 1 time and not a second time.

Who can help me to make a piece of VBA code which works every time?

Thanks, JeroenM.