Excel VBA - Insert latest 2 pictures into a different workbook

Styx

New Member
Joined
Nov 19, 2021
Messages
20
Office Version
  1. 2007
Platform
  1. Windows
Hi all,
I have a automatically runned macro when opening a workbook.
This workbook opens the latest modified workbook in a specific location and adds formulas into different cells of the opened workbook.
And saves the opened workbook with a specific name on a specific location.
And it closes the opened workbook and the workbook with the automated macro when ready.
All good so far.
But I also need to insert 2 of the newest pictures from a specific location into the opened workbook.
I started try try with 1 picture, but I is placed in the workbook with the automated macro and not in the opened (latest modified) workbook.
Below a subroutine which should add a picture in the latest opened workbook and not into the workbook with this macro.
Who can help me out?

Sub CellFilling()

Dim Image_Name As String
Dim Image_Location As String
Dim Image_Format As String
Dim Image As Picture
Dim sActiveWorkbookName As String

sActiveWorkbookName = ActiveWorkbook.Name

Image_Name = "abcd"
Image_Location = "C:\Temp\Pictures"
Image_Format = ".jpg"

Workbooks(sActiveWorkbookName).Activate
Worksheets(1).Activate

Set Image = ActiveSheet.Pictures.Insert(Image_Location & "\" & Image_Name & Image_Format)
With Image
.Top = ActiveSheet.Range("B20").Top
.Left = ActiveSheet.Range("B20").Left
.Width = ActiveSheet.Range("B20").Width
.Height = ActiveSheet.Range("B20").Height
.Placement = 1
End With

With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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