+ Reply to Thread
Results 1 to 2 of 2

VBA and charts: margins and positioning

  1. #1
    Registered User
    Join Date
    11-04-2011
    Location
    Linz
    MS-Off Ver
    Office 2010
    Posts
    13

    VBA and charts: margins and positioning

    Hi there,

    Edit: Problem solved.
    Links to a resource explaining default margin settings and to a complete list of possible settings in a chart (stuff like .ChartArea.Width, .PlotArea.Left and .PlotArea.InsideLeft) still very much appreciated!


    Here I am with another thing that bugs me. I am obviously unable to find a good source where I can find information how to correctly set margins in a graph and how to position objects.

    The short version:
    Are there any margin settings in a chart area that overrule settings like .AxisTitle.Left, .ChartArea.Width and .ChartArea.Left?
    Is there any good resource where e.g. differences between .PlotArea.Left and .PlotArea.InsideLeft are explained?

    The long version:
    Currently, I do position my x-axis labels like this:

    Please Login or Register  to view this content.
    Credits for that go partly to this link. So, this seems to work fine as intended. However, setting the value for the variable "gap" does not match the actual gap between the tick labels and the axis title. Setting gap to zero leads to an overlap between ticks and title. Even a value of 15 produces the same result. Only when further increasing the value it gets formatted as I want it.

    As a result, I can not really control the outcome of my script the way I want it.
    Even worse, what I ultimately want to achieve is that the spacing between the y-axis title and tick labels should match the space between tick labels and axis title on the x-axis. This of course requires knowing the actual distance between axis title and ticks.



    I tried it with:

    Please Login or Register  to view this content.
    and failed.
    I suspect there may be some margins in the chart area that cause problems. This is also because

    Please Login or Register  to view this content.
    as in the code above is obviously not the leftmost place for the axis title as

    Please Login or Register  to view this content.
    pushes it even more to the left (and it is still not touching the left border of the chart). Why?

    So I read the values of ActiveChart.PageSetup.LeftMargin and ActiveChart.PageSetup.BottomMargin and found that they were different. If I correct the value of gap by the double the difference of these values, it seems to deliver the correct result. There has to be a better way to do this. Any ideas?
    Last edited by theDirtyHarry; 11-09-2011 at 01:41 PM. Reason: [SOLVED]

  2. #2
    Registered User
    Join Date
    11-04-2011
    Location
    Linz
    MS-Off Ver
    Office 2010
    Posts
    13

    Re: VBA and charts: margins and positioning

    Solved it.

    If you want to follow, here is what went wrong:

    In the first block of code posted above, I accidentially used

    Please Login or Register  to view this content.
    instead of

    Please Login or Register  to view this content.
    Please, do not ask me why. I don't know.
    After correcting the mistake, everything works fine now. The value for gap can be set reasonably.
    However, I still have to correct ActiveChart.PlotArea.Left by increasing the intended the difference between ActiveChart.PageSetup.MarginBottom and ActiveChart.PageSetup.MarginLeft. The code for the variable pal_new now is defined like this:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1