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
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