dss28
Board Regular
- Joined
- Sep 3, 2020
- Messages
- 165
- Office Version
- 2007
- Platform
- Windows
I want to insert a picture to set the logo of the department in 3 selected sheets via vba code.
By the code given below I am able to insert the picture in only one sheet at a given place and position and size.
when the command button to run the code is clicked, the window to select and attach picture opens three times but it inserts picture only in one sheet.
I want that the window to select and attach a picture should open only once and perform the picture addition in three sheets all at once.
Can anybody help me in providing the code to insert the picture in the three sheets at once?
By the code given below I am able to insert the picture in only one sheet at a given place and position and size.
when the command button to run the code is clicked, the window to select and attach picture opens three times but it inserts picture only in one sheet.
I want that the window to select and attach a picture should open only once and perform the picture addition in three sheets all at once.
Can anybody help me in providing the code to insert the picture in the three sheets at once?
VBA Code:
Sub GetPic()
Dim fNameAndPath As Variant
Dim img As Picture
ThisWorkbook.Sheets("Sheet1").Activate
ThisWorkbook.Sheets("Sheet3").Activate
ThisWorkbook.Sheets("Sheet5").Activate
fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
With img
'Resize Picture to fit in the range....
.ShapeRange.LockAspectRatio = msoFalse ' lock aspect ratio checkbox not selected
.Left = ActiveSheet.Range("E3").Left
.Top = ActiveSheet.Range("E3").Top
.Width = ActiveSheet.Range("E3:G3").Width
.Height = ActiveSheet.Range("E3:E5").Height
.Placement = 1
.PrintObject = True
End With
End Sub