In Excel XP, I've got a macro running to:
1) switch to/from forumla view
2) autofit columns and rows in the used area
3) reset page breaks
4) set the print area and force fit to one landscaped page
It works great, except for leaving charts off of the print area.
I need to figure out what range (or at least the last row) is covered by a chart so I can move the page break below that row.
I have rooted around and found lots of examples of how to make a chart cover a specific range of cells, but what I need is the reverse.
Here's what I've worked up so far. I'm trying to reverse some of the code that I've found, but it's really not working out for me:
Sub CheckChartSize()
Dim iCharts As Integer
Dim objChart As ChartObject
Dim myRange As Range
Set myRange = ActiveSheet.Range("A1:B2")
For iCharts = 1 To ActiveSheet.ChartObjects.Count
ActiveSheet.ChartObjects(iCharts).Activate
Set objChart = ActiveChart.Parent
'these don't work:
myRange.Width = objChart.Width
myRange.Left = ActiveChart.ChartArea.Left
myRange.Height = ActiveChart.Parent.Height
myRange.Width = objChart.Width
myRange.Top = objChart.Top
myRange.Left = objChart.Left
MsgBox myRange
Next iCharts
End Sub
1) switch to/from forumla view
2) autofit columns and rows in the used area
3) reset page breaks
4) set the print area and force fit to one landscaped page
It works great, except for leaving charts off of the print area.
I need to figure out what range (or at least the last row) is covered by a chart so I can move the page break below that row.
I have rooted around and found lots of examples of how to make a chart cover a specific range of cells, but what I need is the reverse.
Here's what I've worked up so far. I'm trying to reverse some of the code that I've found, but it's really not working out for me:
Sub CheckChartSize()
Dim iCharts As Integer
Dim objChart As ChartObject
Dim myRange As Range
Set myRange = ActiveSheet.Range("A1:B2")
For iCharts = 1 To ActiveSheet.ChartObjects.Count
ActiveSheet.ChartObjects(iCharts).Activate
Set objChart = ActiveChart.Parent
'these don't work:
myRange.Width = objChart.Width
myRange.Left = ActiveChart.ChartArea.Left
myRange.Height = ActiveChart.Parent.Height
myRange.Width = objChart.Width
myRange.Top = objChart.Top
myRange.Left = objChart.Left
MsgBox myRange
Next iCharts
End Sub