Renaming Pictures in Excel

  Desert Andy 07:58 10 Mar 2007


i have used the code

iCtr = 1
For Iloop = 1 To ActiveSheet.Shapes.Count
If Left(ActiveSheet.Shapes.Item(Iloop).Name, 7) = "Picture" Then
ActiveSheet.Shapes.Item(Iloop).Name = "Picture" + Str(iCtr)
iCtr = iCtr + 1
End If
Next Iloop
to rename pictures starting from 1.
However, if i have already named a picture such as Picture AndyEvans, I get an error message saying Permission Denied.

Any thoughts please

  VoG II 09:01 10 Mar 2007

As far as I can see from limited testing this occurs if a picture with the same name already exists. You can replicate this by trying to change the name of a picture to a name that already exists by typing the name in the address bar - the name won't change. This is a workaround:

Sub PictureRename()
Dim iLoop As Integer
Dim iCtr As Integer

iCtr = 1
For iLoop = 1 To ActiveSheet.Shapes.Count
If Left(ActiveSheet.Shapes.Item(iLoop).Name, 7) = "Picture" Then
On Error Resume Next
ActiveSheet.Shapes.Item(iLoop).Name = "Picture" & iCtr
On Error GoTo 0
iCtr = iCtr + 1
End If
Next iLoop
End Sub

  Desert Andy 09:05 10 Mar 2007

Thanks very much

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Huawei MateBook X Pro review

8 digital brands that designed custom typefaces to save millions

How to speed up a slow Mac

Comment résoudre des problèmes d’impressions ?