Results 1 to 4 of 4

Thread: Show / Send Copy of Charts into the User Form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Location
    OK - USA
    Posts
    29

    Question Show / Send Copy of Charts into the User Form

    When file is opened the 1st user form says "Welcome" - giving user the option to enter their new monthly metrics (numbers/results) by clicking on "ENTER METRICS"... or click on the "VIEW CHARTS" button to go look at the 4 square of charts.

    The xls. file has 1 tab that holds the database of user input for the year...
    The tab that holds the 4 charts is in: "RE_CHARTS" ...
    The chart names are: CYCLE TIME, EFFICIENCY, TIMELINESS & QUALITY
    They are arranged in a 4-square on the .xls tab

    I'd like this to happen:
    When the user clicks on the CHARTS BUTTON, he's taken to the charts userform and a snapshot of what those charts look like will be sitting there to view. (sent from the charts TAB called: "RG_CHARTS" to the USERFORM called: "frmRGCHARTS"

    Does anyone know VBA code to accomplish this?
    I'm new to VBA and am trying to piece all of this together...
    Thank you VERY much! Chris

    Here's my Welcome form code:
    Code:
    Private Sub cmdCharts_Click()
        frmRGWelcome.Hide
        frmRGCharts.Show
    End Sub
    
    Private Sub cmdMetric_Click()
        frmRGWelcome.Hide
        frmRGUserEntry.Show
    End Sub

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Show / Send Copy of Charts into the User Form

    the easiest way to do this to export a copy of each chart as a picture and them import them into your form. The code below will achieve this.
    I am including it in the _Initialize event of the form, but if you need to refresh teh charts, you should encapsulate it in a seperate sub and call it from the _Initialize event.

    VB Code:
    1. Private Sub UserForm_Initialize()
    2. Dim myChart As Chart
    3. Dim TmpFileName As String
    4.        
    5.     ' The temporary file used to store the picture of
    6.     ' the chart
    7.     TmpFileName = ThisWorkbook.Path & "\tmpChart.gif"
    8.    
    9.     '-----------------------------------------------
    10.     ' Repeat this block for each image and its chart
    11.     '-----------------------------------------------
    12.    
    13.     ' 1 Get a reference to the chart to copy
    14.     Set myChart = Worksheets(1).ChartObjects(1).Chart
    15.    
    16.     ' 2 Export a copy of the chart as a GIF file
    17.     myChart.Export Filename:=TmpFileName, FilterName:="GIF"
    18.    
    19.     ' 3 Import the GIF file to the coresponding control
    20.     ' on my form
    21.     Me.picChart1.Picture = LoadPicture(TmpFileName)
    22.    
    23.     'Repeat the 3 steps above for each chart
    24.    
    25.     '-----------------------------------------------
    26.     ' Afert all charts are copied then delete the
    27.     ' temp file and object variable
    28.     '-----------------------------------------------
    29.     Kill TmpFileName
    30.     Set myChart = Nothing
    31. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Location
    OK - USA
    Posts
    29

    Re: Show / Send Copy of Charts into the User Form

    I'm getting: COMPILE ERROR - Method or Data Member Not Found
    I took out all but 1 chart prior to running to test the posted code without
    the need for duplication (for several charts)

    When I click ok,
    The 'Private Sub UserForm_Initialize()" is highlighted in yellow and
    The "picChart1" is highlighted in blue
    Code:
        ' 3 Import the GIF file to the coresponding control
        ' on my form
        Me.picChart1.Picture = LoadPicture(TmpFileName)
    Any ideas why this is generating?
    I tried to hit F9 (add breakpoint) then re-ran to try to step through w/ F8 but the same thing noted above happens)

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Show / Send Copy of Charts into the User Form

    picChart1 as the name of the image control I used when writing the code above. You need to change it to the name of your image control.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

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



Click Here to Expand Forum to Full Width