如何生成graphics而不花时间使用vba?

你好我已经写了一个代码来生成graphics,它工作正常。 问题是生成需要花费很多时间。 我不明白为什么要花时间。 代码是

Dim cc As Chart Set cc = ActiveWorkbook.Charts.Add Set cc = cc.Location(Where:=xlLocationAsObject, name:=assume) With cc .ChartType = xlXYScatterLines With .Parent .Top = Columns(b).Offset(0, 4).Top .Left = Columns(b).Offset(0, 4).Left .name = "cc" End With End With Dim sc As Series Set sc = cc.SeriesCollection(1) With sc .Values = Columns(b).Offset(0, -3) .XValues = Columns(b).Offset(0, -5) End With 

请有人帮助我

试试这个,只是用实际的数据绘制列的行。

 Sub makeChart(b As String, assume As String) 'i presupposed these arguments based on your code Application.ScreenUpdating = False Dim cc As Chart Set cc = ActiveWorkbook.Charts.Add Set cc = cc.Location(Where:=xlLocationAsObject, Name:=assume) With cc .ChartType = xlXYScatterLines With .Parent .Top = Columns(b).Offset(0, 4).Top .Left = Columns(b).Offset(0, 4).Left .Name = "cc" End With End With Dim strValue As String, strXValue As String 'here you are using the passed column letter to find the specific column you want to chart strValue = Split(Range(b & "1").Offset(, -3).Address, "$")(1) 'will return "C" if given column F strXValue = Split(Range(b & "1").Offset(, -5).Address, "$")(1) 'will return "A" if given column F Dim sc As Series Set sc = cc.SeriesCollection(1) With sc 'will select from row 1 to the last true used row in the given column .Values = Range(strValue & "1:" & strValue & Range(strValue & Rows.Count).End(xlUp).Row) .XValues = Range(strXValue & "1:" & strXValue & Range(strXValue & Rows.Count).End(xlUp).Row) End With Application.ScreenUpdating = True End Sub 

你closures了屏幕更新? 将此添加到您的代码的开头:

 Application.ScreenUpdating = False 

然后在你的代码的最后添加这个:

 Application.ScreenUpdating = True