Chart not loading on Userform

JoyousOne

New Member
Joined
Jan 22, 2025
Messages
3
Office Version
  1. 365
  2. 2024
Platform
  1. Windows
Hi expert,
Hope al of you are doing well, I have some problems loading multiple charts on user form.
I've been using multipage and for each page I save a chart into an object so it can load to the user form, however, I noticed that the chart couldn't reload properly as I run the user form,all I see is an image control without content, I have to transfer from 1 page to another. my goal is to load a chart more than 10-15 pcs.
1. I've been using OneDrive while running, I already tested by saving the tool onto the desktop,but encountered same problem
2. Refreshing sheet, I also done this, but nothing happened

see the screenshot, for what it looks like when I run the user form.
 

Attachments

  • Screenshot 2025-01-23 010635.png
    Screenshot 2025-01-23 010635.png
    6.9 KB · Views: 9
Without seeing any of your code (assuming you have any) I think you can fix this with
DoEvents
Me.Repaint
DoEvents
in the multipage change event. Or you could just try Me.Repaint.
 
Upvote 0
Without seeing any of your code (assuming you have any) I think you can fix this with
DoEvents
Me.Repaint
DoEvents
in the multipage change event. Or you could just try Me.Repaint.
Hi Micron, thank you for answering, here is my code on creating a chart save on directory and this was called upon userform initialization,.I tried GIF but the result the chart was a bit blurry, and when I reloaded the userform, the chart is still invisible at first,my file is located on OneDrive by the way but the charit save on my directory on picture folder.
VBA Code:
Sub UpdateChart(ChartName As String, TargetImageControl As Object)
    Dim CurrentChart As Chart
    Dim FName As String
    Dim SaveFolder As String
    Dim originalWidth As Double
    Dim originalHeight As Double
    Dim AspectRatio As Double

    ' Get the path to the user's Pictures folder
    SaveFolder = Environ("USERPROFILE") & "\Pictures\ChartImages"

    ' Create the folder if it doesn't exist
    If Dir(SaveFolder, vbDirectory) = "" Then
        MkDir SaveFolder
    End If

    ' Define the file name for the chart image
    FName = SaveFolder & "\temp_" & ChartName & ".jpf" ' Unique file name for each chart

    ' Locate the chart
    On Error Resume Next
    Set CurrentChart = ThisWorkbook.Sheets("Dashboard").ChartObjects(ChartName).Chart
    If CurrentChart Is Nothing Then
        MsgBox "Chart not found: " & ChartName, vbCritical
        Exit Sub
    End If
    On Error GoTo 0

    ' Save the original chart dimensions
    originalWidth = CurrentChart.Parent.Width
    originalHeight = CurrentChart.Parent.Height

    ' Clear any existing cached chart image
    On Error Resume Next
    If Dir(FName) <> "" Then
        Kill FName ' Delete the existing file to clear the cache
    End If
    On Error GoTo 0

    ' Export the chart as an image
    On Error Resume Next
    CurrentChart.Export Filename:=FName, FilterName:="JPG"
    If Err.Number <> 0 Then
        MsgBox "Failed to export the chart: " & Err.Description, vbCritical
        Exit Sub
    End If
    On Error GoTo 0

    ' Load the image into the specified UserForm control
    On Error Resume Next
    If Dir(FName) <> "" Then
        With TargetImageControl
            ' Load the chart image
            .Picture = LoadPicture(FName)
            .PictureSizeMode = fmPictureSizeModeZoom ' Maintain aspect ratio


        End With
    Else
        MsgBox "Chart image file not found: " & FName, vbCritical
    End If
    On Error GoTo 0
End Sub
 
Upvote 0
Maybe this will help...

VBA Code:
FName = SaveFolder & "\temp_" & ChartName & ".jpf"
 FName = SaveFolder & "\temp_" & ChartName & ".jpG"
Dave
 
Upvote 0
I don't understand much of that.
- If a folder doesn't exist, that creates it. Then there will be no files in it, so how can you expect ChartName to be there?
- CurrentChart comes from a column of chart names which are chart sheets?
- you're attempting to set CurrentChart to one of those sheets? Then what does that have to do with a folder, empty or not?
- Kill FName: AFAIK, a cache is a browser thing. If the files are not web based (interacting with One Drive is not web based to the best of my knowledge) then I don't see how it's necessary. Besides, you delete the whole folder with that, so then what (refer back to first bullet point)?

-jpf file format seems like overkill for chart images. Also, you are defining file name as jpf
"\temp_" & ChartName & ".jpf"
yet filtering on jpg:
Export Filename:=FName, FilterName:="JPG"

You say you are calling that code upon form open, so it only runs once, so only 1 image control gets a file reference. Yet you say the issue is with switching between tabs. So I'm missing how the other tabs get chart pics in them.

Why are you not just
- ensuring the chart folder exists and has the listed (assuming it is listed) image?
- setting the pic property of the image control to that path on page 1?
- looping to set the other pages to the other listed pic paths (checking as you go)?

Then if you lose the image while switching pages, repaint with the path as suggested.
This seems like a lot of work when you already have chart sheets. Besides, when the underlying data changes, the image is no longer current thus probably needs to be exported and over-written each what - week? day? hour? I might base the chart on a dynamic named range instead and just look at that, then it's always current and eliminate fussy code.
 
Upvote 0
I don't understand much of that.
- If a folder doesn't exist, that creates it. Then there will be no files in it, so how can you expect ChartName to be there?
- CurrentChart comes from a column of chart names which are chart sheets?
- you're attempting to set CurrentChart to one of those sheets? Then what does that have to do with a folder, empty or not?
- Kill FName: AFAIK, a cache is a browser thing. If the files are not web based (interacting with One Drive is not web based to the best of my knowledge) then I don't see how it's necessary. Besides, you delete the whole folder with that, so then what (refer back to first bullet point)?

-jpf file format seems like overkill for chart images. Also, you are defining file name as jpf
"\temp_" & ChartName & ".jpf"
yet filtering on jpg:
Export Filename:=FName, FilterName:="JPG"

You say you are calling that code upon form open, so it only runs once, so only 1 image control gets a file reference. Yet you say the issue is with switching between tabs. So I'm missing how the other tabs get chart pics in them.

Why are you not just
- ensuring the chart folder exists and has the listed (assuming it is listed) image?
- setting the pic property of the image control to that path on page 1?
- looping to set the other pages to the other listed pic paths (checking as you go)?

Then if you lose the image while switching pages, repaint with the path as suggested.
This seems like a lot of work when you already have chart sheets. Besides, when the underlying data changes, the image is no longer current thus probably needs to be exported and over-written each what - week? day? hour? I might base the chart on a dynamic named range instead and just look at that, then it's always current and eliminate fussy code.
Thank you for the quick insights Micron, and yes, the .jpf is already modified, I just noticed it yesterday. I will probably follow what you suggest.
 
Upvote 0

Forum statistics

Threads
1,226,835
Messages
6,193,239
Members
453,782
Latest member
ssg

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