+ Reply to Thread
Results 1 to 2 of 2

Enlarge a Chart

Hybrid View

  1. #1
    Registered User
    Join Date
    10-26-2011
    Location
    sussex
    MS-Off Ver
    Excel 2003
    Posts
    15

    Enlarge a Chart

    I have created a dashboard using Pivot charts and have multiple charts all on the same sheet, but they look quite small
    What I want to be able to do is click a chart and the chart fills the page, click the chart again and it reverts back to its normal size

    Is this possible and how do I go about this

    Thanks in advance

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Enlarge a Chart

    Hi shane1966,

    See the attached file which has been tested on Excel 2003 and 32 bit Excel 2010. 'Left Click' on a Chart to enlarge. 'Left Click' again to restore the chart to it's original position. Macros must be enabled to run the code.

    To port the code to your file:
    a. Export module ModEnlargeRestoreCharts from my file. Import it to your file.
    b. Run Macro AssignMacroToAllChartsOnActiveSheet() on your file.
    c. Save your file.

    Complete code follows:
    Option Explicit
    
    Private myChartLeft As Double
    Private myChartTop As Double
    Private myChartWidth As Double
    Private myChartHeight As Double
    
    
    Sub AssignMacroToAllChartsOnActiveSheet()
      'This will assign a Macro to all Charts on the Active Sheet
      
      Dim Sh As Shape
      
      For Each Sh In ActiveSheet.Shapes
        If Sh.Type = msoChart Then
          Sh.OnAction = "EnlargeOrContractShape"
        End If
      Next Sh
      
    End Sub
    
    Sub RemoveMacrosFromAllChartsOnActiveSheet()
      'This will  unassign Macros from all Charts on the Active Sheet
      
      Dim Sh As Shape
      
      For Each Sh In ActiveSheet.Shapes
        If Sh.Type = msoChart Then
          Sh.OnAction = ""
        End If
      Next Sh
      
    End Sub
    
    Sub EnlargeOrContractShape()
      'This enlarges or contracts a Shape on the 'Active Sheet'
      
      Dim Sh As Shape
      
      Dim dHeight As Double
      Dim dLeft As Double
      Dim dTop As Double
      Dim dWidth As Double
      
      Dim dExcelUsableWidth As Double
      Dim dExcelUsableHeight As Double
      
    
      Dim sName As String
      
      'Get the name of the Shape that called this routine
      On Error Resume Next
      sName = Application.Caller
      
      'Process only if this routine was activated by a Chart
      If Err.Number <> 0 Then
        On Error GoTo 0
        Exit Sub
      End If
      On Error GoTo 0
      
      Set Sh = ActiveSheet.Shapes(sName)
      
      'Exit if the Shape is NOT a Chart
      If Sh.Type <> msoChart Then
        Exit Sub
      End If
      
      'Get the Excel Window Current Usable Width and Current Usable Height
      dExcelUsableWidth = Application.UsableWidth
      dExcelUsableHeight = Application.UsableHeight
      
      'Get the Chart position attributes
      dLeft = Sh.Left
      dTop = Sh.Top
      dWidth = Sh.Width
      dHeight = Sh.Height
      
      
      If myChartWidth = 0# Then
      
        'Save the current (original) Chart position attributes for later restoration
        myChartLeft = dLeft
        myChartTop = dTop
        myChartWidth = dWidth
        myChartHeight = dHeight
      
        'Resize (Maximize) the Chart
        Sh.Left = 5
        Sh.Top = 5
        Sh.Width = dExcelUsableWidth - 40
        Sh.Height = dExcelUsableHeight - 40
        
        'Move the Shape to the Front
        Sh.ZOrder msoBringToFront
        
      Else
      
        'Resize the Shape to it's original position
        Sh.Left = myChartLeft
        Sh.Top = myChartTop
        Sh.Width = myChartWidth
        Sh.Height = myChartHeight
        
        'Reset the sentinel that will allow the chart to be maximized again
        myChartWidth = 0#
        
      End If
    
    End Sub
    To enable Macros and to Run Macros see the following:
    http://office.microsoft.com/en-us/ex...010031071.aspx
    http://office.microsoft.com/en-us/ex...010014113.aspx
    http://office.microsoft.com/en-us/tr...001150634.aspx
    If help is still needed do a google search for 'youtube excel enable macro' and/or 'youtube excel run macro'.

    To access Visual Basic (VBA) see:
    http://www.ablebits.com/office-addin...a-macro-excel/
    a. Click on any cell in the Excel Spreadsheet (may not be needed).
    b. ALT-F11 to get to VBA.
    c. CTRL-R to get project explorer (if it isn't already showing).
    d. Double Click on a 'Module Name' in 'Project Explorer' to see code for that module.

    To import or export VBA code:
    a. To export, right click on the Module Name in the 'Project Explorer'.
    b. Select export file. I suggest you use a SubFolder that only contains exported (.bas) files.
    Keep the original name.
    c. To import, right click anywhere in 'Project Explorer'.
    d. Select import file. Select a file to import.

    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Enlarge and restore an embedded chart from a group of charts
    By Chartguy99 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-11-2014, 12:41 PM
  2. How do I enlarge a pie chart?
    By Weasel in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 11-25-2008, 07:22 PM
  3. how do i enlarge a pie chart by a fixed percentage?
    By ellen s. in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 11-17-2005, 10:10 AM
  4. How to enlarge stacked chart plot area
    By Carole O in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 08-02-2005, 05:05 PM
  5. [SOLVED] How do I enlarge chart size in document?
    By WilkesConcierge in forum Excel General
    Replies: 1
    Last Post: 02-24-2005, 01:06 PM

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