+ Reply to Thread
Results 1 to 8 of 8

to display a graph in a VB userform

Hybrid View

  1. #1
    Registered User
    Join Date
    11-05-2008
    Location
    France
    Posts
    28

    to display a graph in a VB userform

    I would like to have a graph to pulled on to a userform for display purpose.

    I would like to hava a VBA macro to do this operation for a command click event.

    Thanks a lot for your valuable time!

    Taniks

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    See John Walkenbach's tip
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    12-08-2008
    Location
    US
    Posts
    14
    For some odd reason, when I tried that in excel 03, the pasted chart image does not show up unless I literally drag the chart object outside of the visible screen area. When I drag it back, it reappears. Anyone know why this is so?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The example works fine for me in Excel 2003

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Stephen Bullen has a method here, towards the bottom "PastePicture"

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    I named a sheet Charts, and userform1.show from that sheet. Create a Chart on that sheet, add 2 option buttons and 1 image control to the userform.

    Private Sub OptionButton1_Click()
        UpdateChart 1
    End Sub
    Private Sub OptionButton2_Click()
        UpdateChart 2
    End Sub
    
    Private Sub UpdateChart(ChartNum As Integer)
      Dim currentchart As Chart, Fname As String
        Set currentchart = Sheets("Charts").ChartObjects(ChartNum).Chart
        currentchart.Parent.Width = 400
        currentchart.Parent.Height = 200
    
    '   Save chart as GIF
        Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
        currentchart.Export Filename:=Fname, FilterName:="GIF"
    
    '   Show the chart
        Image1.Picture = LoadPicture(Fname)
    End Sub

  7. #7
    Registered User
    Join Date
    11-05-2008
    Location
    France
    Posts
    28
    Thanks a lot for all your replies!

    I will try it out and inform you all !


    Thanks a lot for ur time again!

    Regards
    Taniks

  8. #8
    Registered User
    Join Date
    11-05-2008
    Location
    France
    Posts
    28

    code works

    I would like to thank Roy and Kenneth for their solution to my query!

    I apologise for my late reply!


    Thanks for your time !

    Regards
    Taniks

+ 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