Renaming Pictures in Excel

  Desert Andy 07:58 10 Mar 07


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 07

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 07

Thanks very much

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

Intel Coffee Lake 8th-gen Core processors release date rumours

1995-2015: How technology has changed the world in 20 years

Framestore’s haunting post-WWII title sequence for new BBC series SS-GB

How to install MacOS Sierra on an older Mac: Get Sierra running on Macs & MacBooks from before 2009