|
-
Jan 21st, 2006, 04:43 PM
#1
Thread Starter
Junior Member
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
-
Jan 23rd, 2006, 06:00 PM
#2
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:
Private Sub UserForm_Initialize()
Dim myChart As Chart
Dim TmpFileName As String
' The temporary file used to store the picture of
' the chart
TmpFileName = ThisWorkbook.Path & "\tmpChart.gif"
'-----------------------------------------------
' Repeat this block for each image and its chart
'-----------------------------------------------
' 1 Get a reference to the chart to copy
Set myChart = Worksheets(1).ChartObjects(1).Chart
' 2 Export a copy of the chart as a GIF file
myChart.Export Filename:=TmpFileName, FilterName:="GIF"
' 3 Import the GIF file to the coresponding control
' on my form
Me.picChart1.Picture = LoadPicture(TmpFileName)
'Repeat the 3 steps above for each chart
'-----------------------------------------------
' Afert all charts are copied then delete the
' temp file and object variable
'-----------------------------------------------
Kill TmpFileName
Set myChart = Nothing
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jan 24th, 2006, 05:34 PM
#3
Thread Starter
Junior Member
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)
-
Jan 24th, 2006, 05:35 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|