Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Mark
 
Posts: n/a
Default Scaling a chart that has been dynamically created in vb

I've got a VB app that creates charts based on data selections made by the
user. over time, the stuff in the DB will grow, so there's no easy way to
predict what the size of the chart should be. When it's built, it gets dumped
into a worksheet set aside just for that chart, along with some cells in
which various accumulations (monthly capcity, etc) get posted.

At the moment, the default size of the chart is 'small', (top left at cell
f13, bot-rt at cell p38). I'd like the chart to go from a1 to p38 (or
thereabouts), regardless of the number of data elements used to create it.

I have a book (Excel 2003 VBA Prog ref) that describes the excel obj model.
it implies there are some interesting methods that might be used to set TL
location and height & width -- but it's short on code examples on *how* to do
this.

Any pointers would be very welcome.

Thanks,
Mark (vb newbie)
  #2   Report Post  
Andy Pope
 
Posts: n/a
Default

Hi,

This is VBA code which runs within xl so you may need to tweak the
declaration of objCht and the use of Range to suit your vb app.

Sub SizeChart()
Dim objCht As ChartObject
Set objCht = ActiveSheet.ChartObjects(1)
With Range("A1:P38")
objCht.Left = .Left
objCht.Top = .Top
objCht.Width = .Width
objCht.Height = .Height
End With
End Sub

Cheers
Andy

Mark wrote:
I've got a VB app that creates charts based on data selections made by the
user. over time, the stuff in the DB will grow, so there's no easy way to
predict what the size of the chart should be. When it's built, it gets dumped
into a worksheet set aside just for that chart, along with some cells in
which various accumulations (monthly capcity, etc) get posted.

At the moment, the default size of the chart is 'small', (top left at cell
f13, bot-rt at cell p38). I'd like the chart to go from a1 to p38 (or
thereabouts), regardless of the number of data elements used to create it.

I have a book (Excel 2003 VBA Prog ref) that describes the excel obj model.
it implies there are some interesting methods that might be used to set TL
location and height & width -- but it's short on code examples on *how* to do
this.

Any pointers would be very welcome.

Thanks,
Mark (vb newbie)


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #3   Report Post  
Mark
 
Posts: n/a
Default

Hi Andy --- THanks for the code segment -- it works -- but it scales the
(apparently remembered) first ever created chart (chart 1). The current
number (monotonically increasinG is ine the 40's or 50's.

SO I guess the next question is either

a) How do I programmatically determine the number of the current chart?, or
b) How do I erase the app's knowledge of prior chart definitions and/or set
the current chart to a known (e.g. "1" ) value?

Or perhaps there's a c) I'm not VB-literate enough to think of.

Thanks again for your help.

Mark

"Andy Pope" wrote:

Hi,

This is VBA code which runs within xl so you may need to tweak the
declaration of objCht and the use of Range to suit your vb app.

Sub SizeChart()
Dim objCht As ChartObject
Set objCht = ActiveSheet.ChartObjects(1)
With Range("A1:P38")
objCht.Left = .Left
objCht.Top = .Top
objCht.Width = .Width
objCht.Height = .Height
End With
End Sub

Cheers
Andy

Mark wrote:
I've got a VB app that creates charts based on data selections made by the
user. over time, the stuff in the DB will grow, so there's no easy way to
predict what the size of the chart should be. When it's built, it gets dumped
into a worksheet set aside just for that chart, along with some cells in
which various accumulations (monthly capcity, etc) get posted.

At the moment, the default size of the chart is 'small', (top left at cell
f13, bot-rt at cell p38). I'd like the chart to go from a1 to p38 (or
thereabouts), regardless of the number of data elements used to create it.

I have a book (Excel 2003 VBA Prog ref) that describes the excel obj model.
it implies there are some interesting methods that might be used to set TL
location and height & width -- but it's short on code examples on *how* to do
this.

Any pointers would be very welcome.

Thanks,
Mark (vb newbie)


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

  #4   Report Post  
Andy Pope
 
Posts: n/a
Default

You could use this to always deal with the last chart object.

Set objCht = ActiveSheet.ChartObjects(ActiveSheet.ChartObjects. count)

Mark wrote:
Hi Andy --- THanks for the code segment -- it works -- but it scales the
(apparently remembered) first ever created chart (chart 1). The current
number (monotonically increasinG is ine the 40's or 50's.

SO I guess the next question is either

a) How do I programmatically determine the number of the current chart?, or
b) How do I erase the app's knowledge of prior chart definitions and/or set
the current chart to a known (e.g. "1" ) value?

Or perhaps there's a c) I'm not VB-literate enough to think of.

Thanks again for your help.

Mark

"Andy Pope" wrote:


Hi,

This is VBA code which runs within xl so you may need to tweak the
declaration of objCht and the use of Range to suit your vb app.

Sub SizeChart()
Dim objCht As ChartObject
Set objCht = ActiveSheet.ChartObjects(1)
With Range("A1:P38")
objCht.Left = .Left
objCht.Top = .Top
objCht.Width = .Width
objCht.Height = .Height
End With
End Sub

Cheers
Andy

Mark wrote:

I've got a VB app that creates charts based on data selections made by the
user. over time, the stuff in the DB will grow, so there's no easy way to
predict what the size of the chart should be. When it's built, it gets dumped
into a worksheet set aside just for that chart, along with some cells in
which various accumulations (monthly capcity, etc) get posted.

At the moment, the default size of the chart is 'small', (top left at cell
f13, bot-rt at cell p38). I'd like the chart to go from a1 to p38 (or
thereabouts), regardless of the number of data elements used to create it.

I have a book (Excel 2003 VBA Prog ref) that describes the excel obj model.
it implies there are some interesting methods that might be used to set TL
location and height & width -- but it's short on code examples on *how* to do
this.

Any pointers would be very welcome.

Thanks,
Mark (vb newbie)


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
add line to a stacked area chart already created Mitch Charts and Charting in Excel 3 April 3rd 23 04:43 PM
Urgent Chart Assistance Brent E Charts and Charting in Excel 1 May 10th 05 09:09 AM
Urgent Chart Questions Brent E Excel Discussion (Misc queries) 0 May 9th 05 11:01 PM
Urgent Chart Assistance Requested Brent E Excel Discussion (Misc queries) 0 May 9th 05 11:01 PM
Dynamically chart active row Patti Charts and Charting in Excel 7 April 4th 05 03:39 PM


All times are GMT +1. The time now is 12:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"