Renaming multiple copied pictures in VBA

Tev123

New Member
Joined
Jul 9, 2019
Messages
3
Hi,

I am copying charts from one excel workbook (model1), and pasting them in a second excel workbook (TempFile) as a picture. There are roughly 60 of these images. I would like to rename these images. The image names keep changing, which leads to problems for the next steps.

Does anyone know how I can simply, run a loop that would just rename all the pictures in the workbook according to a count.
Example, the first picture on sheet1 be called "Picture1", next picture be called "Picture2". Each picture through out the workbook subsequently follows that order.

Thank you in advance.

I have this which I found online, but not sure how to add a count or rename to this.

Sub LoopThroughCharts()


Dim sht As Worksheet
Dim CurrentSheet As Worksheet
Dim cht As ChartObject

Application.ScreenUpdating = False
Application.EnableEvents = False

Set CurrentSheet = ActiveSheet

For Each sht In ActiveWorkbook.Worksheets
For Each cht In sht.ChartObjects
cht.Activate

'Do something with the chart...

Next cht
Next sht

CurrentSheet.Activate
Application.EnableEvents = True

End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Welcome to MrExcel forums.

How about this -
Code:
Public Sub Rename_Pictures()
    
    Dim ws As Worksheet
    Dim pic As Picture
    Dim i As Long
    
    i = 0
    For Each ws In ActiveWorkbook.Worksheets
        For Each pic In ws.Pictures
            i = i + 1
            pic.Name = "Picture" & i
        Next
    Next
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top