Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Problem in graph automation in excel.

Hi.

I have a strange problem in a VB-macro, trying to specify the plot area on a
chart.

If I step through the code, everything works aps intended, and afterwards
pl1 = pl, pw2 = pw and ph1 = ph.

If I let the code run without interruption, the plot area is not set
corrctly, and pl1 < pl, pw2 < pw and ph1 < ph afterwards.
The values of pl, ph and pw are correct.

That is the problem?

pl = Int(chartlengde * 0.05)
ph = Int(charthoyde * 0.7)
pw = Int(chartlengde * 0.9)
Sheets(ark).ChartObjects("Chart 1").Chart.PlotArea.Top = 16
Sheets(ark).ChartObjects("Chart 1").Chart.PlotArea.Left = pl
Sheets(ark).ChartObjects("Chart 1").Chart.PlotArea.Height = ph
Sheets(ark).ChartObjects("Chart 1").Chart.PlotArea.Width = pw
Sheets(ark).ChartObjects("Chart 1").Chart.PlotArea.Interior.ColorIndex =
xlNone
pl1 = Sheets(ark).ChartObjects("Chart 1").Chart.PlotArea.Left
pw1 = Sheets(ark).ChartObjects("Chart 1").Chart.PlotArea.Width
ph1 = Sheets(ark).ChartObjects("Chart 1").Chart.PlotArea.Height

Best regards

Einar Værnes


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Problem in graph automation in excel.

Assuming that "ark" is the name on the worksheet tab, change each instance
of Sheets(ark) to Sheets("ark"). The sheet name has to have double quotes
around it. Better yet, use Worksheets("ark").

Also, to simplify, you can factor out Sheets(ark).ChartObjects("Chart
1").Chart.PlotArea on each line and use a With statement instead. Make sure
that there is still a period in each location where this string is removed.
This makes the code much easier to read and maintain. The code will also run
faster, since Excel does not have to perform so many object accesses at
runtime.

pl = Int(chartlengde * 0.05)
ph = Int(charthoyde * 0.7)
pw = Int(chartlengde * 0.9)

With Worksheets("ark").ChartObjects("Chart 1").Chart.PlotArea
.Top = 16
.Left = pl
.Height = ph
.Width = pw
.Interior.ColorIndex = xlNone
pl1 = .Left
pw1 = .Width
ph1 = .Height
End With

--
Regards,
Bill


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Problem in graph automation in excel.

Thanks for your answer.

1) ark is a string variable containing the sheet name. This is part of a sub, accepting different sheet names.

2) At first I used the With statement, but got the same problems then.
I changed to full reference to be sure that I referenced the right object - but with no apparent effect.

3) I think I have now solved the problem by putting the the statement Sheets(ark).Select in front of the rest of the code.
I can not see why I should need that, because I explicitly reference the chart with
With Sheets(ark).ChartObjects("Chart 1").Chart
..
..
End with

I also have a lot of other statements in the With-context that executes without problems.

What I really think is strange, is that I set some properties on the PlotArea,
and when I read them back in the next statement, I get other values than those I just set.
It all woks perfectly when I step through the code, but not when run uninterrupted.

Looks like a VB bug to me.

Best regards

Einar Værnes

"Bill Renaud" wrote in message ...
Assuming that "ark" is the name on the worksheet tab, change each instance
of Sheets(ark) to Sheets("ark"). The sheet name has to have double quotes
around it. Better yet, use Worksheets("ark").

Also, to simplify, you can factor out Sheets(ark).ChartObjects("Chart
1").Chart.PlotArea on each line and use a With statement instead. Make sure
that there is still a period in each location where this string is removed.
This makes the code much easier to read and maintain. The code will also run
faster, since Excel does not have to perform so many object accesses at
runtime.

pl = Int(chartlengde * 0.05)
ph = Int(charthoyde * 0.7)
pw = Int(chartlengde * 0.9)

With Worksheets("ark").ChartObjects("Chart 1").Chart.PlotArea
.Top = 16
.Left = pl
.Height = ph
.Width = pw
.Interior.ColorIndex = xlNone
pl1 = .Left
pw1 = .Width
ph1 = .Height
End With

--
Regards,
Bill


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Problem in graph automation in excel.

<<ark is a string variable containing the sheet name. This is part of a sub,
accepting different sheet names.
Ah ha. I didn't think about the fact that you might be using a variable.
Normally, you are supposed to use object variables to point to the object.
If the worksheet being referenced by the code is not the active worksheet,
then these types of problems result.

So, at the top of your code, you should add variables to reference the
worksheet and chart, then set them to the worksheet and chart, like so:

Dim ws as Worksheet
Dim crt as ChartObject
'Other variable declarations.

Set ws = Worksheets(ark)
Set crt = ws.ChartObjects("Chart 1")

With crt.Chart.PlotArea
'Code to set and check PlotArea properties.
End With

I had these problems a lot also in the early days of learning Excel VBA
macro programming. (Time to buy a couple of books or visit the
http://www.mvps.org/links.html#Excel page and see what they might have.)
--
Hope this helps (HTH),
Regards,
Bill


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
Problem with excel macro - getting automation error [email protected] Charts and Charting in Excel 3 October 24th 07 05:22 PM
Excel 2003 c++ automation problem. Ken Excel Worksheet Functions 0 January 9th 07 12:13 AM
Excel Automation Problem with Late Binding mflorezm Excel Programming 0 November 16th 04 06:03 PM
TypeConverter Excel-Automation problem Markus Excel Programming 0 August 23rd 04 11:17 AM
Problem with quitting Excel opened through automation Michelle Excel Programming 2 January 8th 04 06:54 PM


All times are GMT +1. The time now is 03:27 PM.

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

About Us

"It's about Microsoft Excel"