当谈到VBA时,我是新手,但基本上我想创建一个宏,然后我可以用它来运行多个工作表。我有很多数据。
到目前为止我所做的是使用excel中的宏录制功能来制作图表然后保存它。这很好用,每次在同一张纸上运行我的图表。但是,当我尝试在不同的工作表中运行它时,它只是从上一个工作表生成一个图表。我在线查看并尝试将源名称编辑为ActiveSheet!但它没有奏效。这是我的代码:
最小保存
Sub 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
End Sub
如果有人可以帮助我,我将不胜感激。谢谢你的时间。
答案 0 :(得分:0)
您可以将宏另存为加载项。启动excel时可以使用它。 您也可以分发加载项。
否则,您可以将宏添加到您的个人书中。