I am having issues with resizing images in VBA. I have tried a bunch of methods and here is the code that I am using:
Sub Macro17()
'
' Macro17 Macro
'
'
Call Macro1
Call Macro2
End Sub
Sub Macro1()
Sheets("Data").Select
Range("A77:N79").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Range("A58:N58,A77:N79")
With ActiveChart
'chart name
.SetElement (msoElementChartTitleAboveChart)
.ChartTitle.Text = " Plot 1"
'X axis name
'.Axes(xlCategory, xlPrimary).HasTitle = True
'.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X-Axis"
'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "y - label"
End With
ActiveChart.Parent.Cut
Sheets("Plots").Select
ActiveSheet.Paste Destination:=Worksheets("Plots").Range("B2:B5")
With ActiveChart.Parent
.Height = 369
.Width = 520
End With
End Sub
Sub Macro2()
Sheets("Data").Select
Range("A83:N85").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Range("A58:N58,A83:N85")
With ActiveChart
'chart name
.SetElement (msoElementChartTitleAboveChart)
.ChartTitle.Text = " Plot Two"
'X axis name
'.Axes(xlCategory, xlPrimary).HasTitle = True
'.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X-Axis"
'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "y - label"
End With
ActiveChart.Parent.Cut
Sheets("Plots").Select
ActiveSheet.Paste Destination:=Worksheets("Plots").Range("B30:B35")
With ActiveChart.Parent
.Height = 369
.Width = 520
End With
ActiveChart.Axes(xlCategory).TickLabelPosition = xlTickLabelPositionLow
End Sub
So I use Macro17, to call both Macro1 and Macro2, and then plot the appropriate data, my issue is that when I call Macro17, only the first plot is made bigger. When I run through both macros with the debugger using F8 (in windows) I have no issues and the code runs as expeceted, but this is extremely in efficient. It probably has to do with how ActiveChart.Parent
is used. Thank you for all your help it is much appreciated.