Formatting Chart to Fit Image Box

  • Hi there,
    I've created a chart from excel and saved it as a gif file. I now want to fit it into the image box on my user form.


    At present the imagebox only shows around half the chart as it needs to be much bigger, or the picture much smaller - can i dynamically format the gif file to fit the image box?
    Thanks,
    John

  • Re: Formatting Chart to Fit Image Box


    John


    I don't know about dynamically but aren't there properties of an image control (PictureSizeMode, is one of the top of my head) that will determine how a picture is displayed.

  • Re: Formatting Chart to Fit Image Box


    Hi Norie,
    I've used picture alingment and picture size mode to no effect.
    The size mode is zoom, stretch and 0, which is default i guess.The alignment is top, bottom, right/left.


    Any other ideas?
    thanks,
    John

  • Re: Formatting Chart to Fit Image Box


    hi,
    no good - it still doesn't fit.
    This is the vba code i use to create and insert the graph, if that helps.
    I changed the image-box to stretch mode on the user form itself, but no dice.
    Thanks,
    John


    [vba]Private Sub CommandButton2_Click()
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Sheet11").Range("A1:J11"), PlotBy _
    :=xlRows
    ActiveChart.Location Where:=xlLocationAsNewSheet
    With ActiveChart
    .HasTitle = True
    .ChartTitle.Characters.Text = "Ge for Selected Thickness"
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Equations"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Ge Value"
    End With
    With ActiveChart
    .HasAxis(xlCategory, xlPrimary) = True
    .HasAxis(xlValue, xlPrimary) = True
    End With
    ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
    ActiveChart.HasDataTable = False

    Fname = ThisWorkbook.Path & "\" & ActiveChart.Name & ".gif"
    ActiveChart.Export Filename:=Fname, FilterName:="GIF"
    Image1.Picture = LoadPicture(Fname)
    End Sub[/vba]

  • Re: Formatting Chart to Fit Image Box


    Hi,
    Setting the Image picture size mode to stretch worked as expected for me. Image of chart filled the control.
    [vba]Private Sub CommandButton2_Click()
    Dim fname As String
    Charts.Add
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=Sheets("Sheet11").Range("A1:J11"), PlotBy _
    :=xlRows
    ActiveChart.Location Where:=xlLocationAsNewSheet
    With ActiveChart
    .HasTitle = True
    .ChartTitle.Characters.Text = "Ge for Selected Thickness"
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Equations"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Ge Value"
    End With
    With ActiveChart
    .HasAxis(xlCategory, xlPrimary) = True
    .HasAxis(xlValue, xlPrimary) = True
    End With
    ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
    ActiveChart.HasDataTable = False


    fname = ThisWorkbook.Path & "\" & ActiveChart.Name & ".gif"
    ActiveChart.Export Filename:=fname, FilterName:="GIF"
    Image1.Picture = LoadPicture(fname)
    Image1.PictureSizeMode = fmPictureSizeModeStretch
    End Sub[/vba]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!