Av8tordude
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 1,075
- Office Version
- 2019
- Platform
- Windows
When running this code, the code executes very quick on a sheet with (ex. 300 used range). However, if I run this code on sheet with (ex 750 used range) its bogs down at a ChartObjects.Add. Doing some searching, I came across similar issue here... Creating a Chart Is VERY Slow
Only issue is that I'm not using any data. The code only adds a PNG image to the sheet then copies that image to a chart object so I can load it to a userform. Any idea why its executing slow and what I can do to speed up loading the chart object?
Only issue is that I'm not using any data. The code only adds a PNG image to the sheet then copies that image to a chart object so I can load it to a userform. Any idea why its executing slow and what I can do to speed up loading the chart object?
VBA Code:
Option Explicit
Private Sub UserForm_Activate()
Dim myPicture As String, FName As String
Dim Pict As Object, oChartObj As ChartObject
Set Wks = ActiveSheet
Wks.Unprotect Password:="Password"
Application.ScreenUpdating = False
lbTitle = Range("A" & ActiveCell.Row) & " - " & Range("B" & ActiveCell.Row)
Set Pict = Wks.Pictures.Insert(ActiveCell.Comment.Text)
Pict.Name = "i" & ActiveCell.Value
myPicture = "i" & ActiveCell.Value
With Pict
.ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Width = 500
.ShapeRange.Height = 500
End With
Set oChartObj = Wks.ChartObjects.Add(Top:=0, Left:=0, Width:=805, Height:=417)
With Wks
.Shapes(myPicture).Copy
With oChartObj.Chart
.ChartArea.Select
.Paste
End With
FName = Environ("temp") & "\temp.gif"
.ChartObjects(5).Chart.Export FName
Image2.Picture = LoadPicture(FName)
oChartObj.Delete
.Shapes(myPicture).Delete
Kill FName
End With
Wks.Protect Password:="Password"
Application.ScreenUpdating = True
End Sub