Display Graph in Userform

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I have this code that generates a graph. I would like to display the graph in a userform. I'm getting an error and I'm not sure why. Please help.

Thanks

Code:
Sub MyCandlestick()Dim OHLCChart As ChartObject
Dim LRow As Long
Dim ChartName As String, fname As String


LRow = Range("AA" & Rows.Count).End(xlUp).Row
Set OHLCChart = ActiveSheet.ChartObjects.Add(Left:=Range("A15").Left, Width:=400, Top:=Range("A15").Top, Height:=250)


With OHLCChart.Chart
    .SetSourceData Source:=ActiveSheet.Range("AA1:AE" & LRow) ' & nRows)
    .ChartType = xlStockOHLC
    .HasTitle = True
    .ChartTitle.Text = cbName
    .Axes(xlValue, xlPrimary).HasTitle = False
    .HasLegend = False
    .PlotArea.Format.Fill.ForeColor.RGB = RGB(220, 230, 241)
    
    With .ChartGroups(1)
        .UpBars.Format.Fill.ForeColor.RGB = RGB(0, 176, 80)
        .DownBars.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
    End With
    
    .ChartArea.Format.Line.Visible = msoFalse
    .Parent.Name = "OHLC Chart"
    .Axes(xlCategory).CategoryType = xlCategoryScale
End With


fname = Application.DefaultFilePath & Application.PathSeparator & "TempChart.gif"
OHLCChart.Export Filename:=fname, FilterName:="GIF"


frmData.Image.Picture = LoadPicture(fname)
ActiveSheet.ChartObjects(1).Delete
Kill fname
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Code:
frmData.Image1.Picture = LoadPicture(fname)
The image control is likely called image1. HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top