Please HELP - strange VBA problem

mpeline
NewLounger
Posts: 3
Joined: 20 Aug 2023, 17:03

Please HELP - strange VBA problem

Post by mpeline »

I am trying to extract thumbnails from an excel sheet and i am getting this error.
image001.jpg
It works on some computers - but not on others, all running Windows 11, even one of the computers that are able to run the code are still running Windows 7.
There are no obvious relation between ram and processor power.
I have tried everything but nothing works, so please help.

This is the code:
'*****************************
Sub ExtractPictures()
Dim LR As Long

Application.ScreenUpdating = False

fld = ActiveWorkbook.Path
LR = Cells(Rows.Count, 1).End(xlUp).Row
Dim cht As ChartObject
Dim ActiveShape As Shape
Dim UserSelection As Variant
i = 1

For x = 1 To LR - 1
'Ensure a Shape is selected
'On Error GoTo NoShapeSelected

ActiveSheet.Shapes.Range(Array("Picture " & i)).Select

Set UserSelection = ActiveWindow.Selection
Set ActiveShape = ActiveSheet.Shapes(UserSelection.Name)


'Create a temporary chart object (same size as shape)
Set cht = ActiveSheet.ChartObjects.Add( _
Left:=ActiveCell.Left, _
Width:=ActiveShape.Width, _
Top:=ActiveCell.Top, _
Height:=ActiveShape.Height)

'Format temporary chart to have a transparent background
cht.ShapeRange.Fill.Visible = msoFalse
cht.ShapeRange.Line.Visible = msoFalse

'Copy/Paste Shape inside temporary chart

ActiveShape.Copy
cht.Activate
ActiveChart.Paste

'Save chart


cht.Chart.Export fld & "/" & ActiveShape.Name & ".png"

'Delete temporary Chart
cht.Delete
' Clear the clipboard
Application.CutCopyMode = False

'Re-Select Shape (appears like nothing happened!)
ActiveShape.Select
' Clear the clipboard
Application.CutCopyMode = False
Set cht = Nothing
Set UserSelection = Nothing
Set ActiveShape = Nothing

i = i + 1
Next x
Application.ScreenUpdating = True

End Sub
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Please HELP - strange VBA problem

Post by HansV »

Could you attach a small sample workbook demonstrating the problem (without sensitive data)?
Best wishes,
Hans

snb
4StarLounger
Posts: 584
Joined: 14 Nov 2012, 16:06

Re: Please HELP - strange VBA problem

Post by snb »

Install Irfanview (if you haven't already)
Then use:

Code: Select all

Sub M_snb()
  c00 = "F:\Irfanview\" & Dir("F:\Irfanview\" & "i_view*.exe")

  For Each it In Shapes
    it.CopyPicture
    Shell c00 & " /clippaste /convert=G:\OF\" & it.Name & ".png", 0
  Next
End Sub
NB.
- adapt the location 'F:\Irfanview' to where Irfanview on your system resides
- adapt the location 'G:\OF' where the picturefiles have to be stored.