Av8tordude
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 1,075
- Office Version
- 2019
- Platform
- Windows
I have this code that takes a PNG picture on a sheet and saves it as a GIF image and then uploads to a userform image. Sometimes it works, but most of the time, I get this image? Can someone tell me why this image appears?
VBA Code:
Private Sub tgImage_Click()
Dim MyChart As String, MyPicture As String, FName As String
Dim PicWidth As Long, PicHeight As Long, Pict As Object
Dim oChartObj As ChartObject
If tgImage = False Then
Image2.Picture = LoadPicture("")
Image2.Visible = False
Else
Application.ScreenUpdating = False
Set Pict = ActiveSheet.Pictures.Insert(ActiveCell.Comment.Text)
With Pict
.ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Width = 650
.ShapeRange.Height = 650
End With
Pict.Name = ActiveCell.Value
MyPicture = ActiveCell.Value
Set oChartObj = ActiveSheet.ChartObjects.Add(Top:=0, Left:=0, Width:=600, Height:=300)
With ActiveSheet
.Shapes(MyPicture).Copy
With oChartObj.chart
.ChartArea.Select
.Paste
End With
FName = VBA.Environ("TEMP") & Application.PathSeparator & "MyPic.Gif"
.ChartObjects(1).chart.Export FName
Image2.Visible = True
Image2.Picture = LoadPicture(FName)
oChartObj.Delete
.Shapes(MyPicture).Delete
Kill FName
End With
End If
End Sub