0
我是菜鳥,當涉及到VBA時,但基本上我想創建一個宏,然後我可以使用它在多張表中運行。我有很多數據。使宏獨立,用於在excel中生成多張圖表
我到目前爲止所做的是使用Excel中的宏記錄功能來製作圖形然後保存它。這工作正常,我的圖形每次在同一張紙上運行時生成。但是,當我嘗試在不同的工作表中運行它時,它只是從上一張工作表生成一個圖表。我在網上查找並嘗試將源名稱編輯爲ActiveSheet!但它沒有奏效。這裏是我的代碼:
敏退役保存
子minret_v1() ' ' minret_v1宏 '
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""0"""
ActiveChart.FullSeriesCollection(1).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(1).Values = "='20160916 Acell 1'!$B$6:$B$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""50"""
ActiveChart.FullSeriesCollection(2).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(2).Values = _
"='20160916 Acell 1'!$D$953:$D$1033"
ActiveChart.FullSeriesCollection(2).Values = "='20160916 Acell 1'!$D$6:$D$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(3).Name = "=""100"""
ActiveChart.FullSeriesCollection(3).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(3).Values = "='20160916 Acell 1'!$F$6:$F$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(4).Name = "=""150"""
ActiveChart.FullSeriesCollection(4).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(4).Values = "='20160916 Acell 1'!$H$6:$H$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(5).Name = "=""200"""
ActiveChart.FullSeriesCollection(5).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(5).Values = "='20160916 Acell 1'!$J$6:$J$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(6).Name = "=""250"""
ActiveChart.FullSeriesCollection(6).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(6).Values = "='20160916 Acell 1'!$L$6:$L$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(7).Name = "=""300"""
ActiveChart.FullSeriesCollection(7).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(7).Values = "='20160916 Acell 1'!$N$6:$N$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(8).Name = "=""350"""
ActiveChart.FullSeriesCollection(8).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(8).Values = "='20160916 Acell 1'!$P$6:$P$1033"
ActiveWindow.ScrollRow = 993
ActiveWindow.ScrollRow = 987
ActiveWindow.ScrollRow = 970
ActiveWindow.ScrollRow = 945
ActiveWindow.ScrollRow = 897
ActiveWindow.ScrollRow = 761
ActiveWindow.ScrollRow = 494
ActiveWindow.ScrollRow = 431
ActiveWindow.ScrollRow = 356
ActiveWindow.ScrollRow = 237
ActiveWindow.ScrollRow = 214
ActiveWindow.ScrollRow = 165
ActiveWindow.ScrollRow = 142
ActiveWindow.ScrollRow = 109
ActiveWindow.ScrollRow = 89
ActiveWindow.ScrollRow = 80
ActiveWindow.ScrollRow = 52
ActiveWindow.ScrollRow = 46
ActiveWindow.ScrollRow = 38
ActiveWindow.ScrollRow = 37
ActiveWindow.ScrollRow = 35
ActiveWindow.ScrollRow = 34
ActiveWindow.ScrollRow = 32
ActiveWindow.ScrollRow = 31
ActiveWindow.ScrollRow = 29
ActiveWindow.ScrollRow = 28
ActiveWindow.ScrollRow = 25
ActiveWindow.ScrollRow = 16
ActiveWindow.ScrollRow = 8
ActiveWindow.ScrollRow = 1
ActiveChart.ApplyChartTemplate (_
"C:\Users\Santiago\AppData\Roaming\Microsoft\Templates\Charts\Mult Lines_decay.crtx" _
)
ActiveChart.Axes(xlValue).AxisTitle.Select
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "gamma(nm)"
Selection.Format.TextFrame2.TextRange.Characters.Text = "gamma(nm)"
With Selection.Format.TextFrame2.TextRange.Characters(1, 9).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 9).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "Arial"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "Arial"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.Axes(xlCategory).AxisTitle.Select
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = _
"Distance from interaction"
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Distance from interaction"
With Selection.Format.TextFrame2.TextRange.Characters(1, 25).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 25).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "Arial"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "Arial"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Acell 20160916"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Acell 20160916"
With Selection.Format.TextFrame2.TextRange.Characters(1, 14).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 14).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "Arial"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 21.6
.Italic = msoFalse
.Kerning = 12
.Name = "Arial"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.ChartArea.Select
Range("R10").Select
末次
如果有人可以幫助我,它會是多少讚賞。感謝您的時間。