Hi All,
Need help in opening multiple excel file 1 by 1 and pasting the image in two sheets named "MCU" and "Summary" in a cell. I am able to open first excel file and able to paste it the image in two sheets but not able to do it in others excel file present in folders. There may a many as excel file in a folder.
Please find below code which I have tried.
Any help is appreciated as this little urgent. Thanks in advance.
Below is main code for opening multiple excel file
Below code is PasteImage method.
Need help in opening multiple excel file 1 by 1 and pasting the image in two sheets named "MCU" and "Summary" in a cell. I am able to open first excel file and able to paste it the image in two sheets but not able to do it in others excel file present in folders. There may a many as excel file in a folder.
Please find below code which I have tried.
Any help is appreciated as this little urgent. Thanks in advance.
Below is main code for opening multiple excel file
Code:
Sub FileImageCopy()
Dim i As Integer
Dim j As Integer
Dim Fname As Variant
Dim Path As Variant
Dim Imagename As Variant
Dim wbk, wbk1 As Workbook
Dim ws As Worksheet
Dim sh As Shape
Dim p As Object
Dim a As Single
Dim Ha As Object
Dim Wa As Object
Path = "C:\Users\611892636\desktop\Paste Pic\" 'change according to your location
If Right(Path, 1) <> "\" Then Path = Path + "\"
Fname = Dir(Path & "*.xlsm")
Do While Fname <> ""
Application.ScreenUpdating = False
Set wbk = Workbooks.Open(Path & Fname)
Call PasteImage 'calling method for paasting the image in excel files to two sheets
Fname = Dir
Loop
Application.ScreenUpdating = True
End Sub
Below code is PasteImage method.
Code:
Sub PasteImage()
Dim i As Integer
Dim j As Integer
Dim Imagename As Variant
Dim Fpath As Variant
Dim wbk As Workbook
Dim ws As Worksheet
Dim sh As Shape
Dim p As Object
Dim a As Single
Dim Ha As Object
Dim Wa As Object
Fpath = "C:\Users\611892636\desktop\Paste Pic\" 'change according to your location
If Right(Fpath, 1) <> "\" Then Fpath = Fpath + "\"
Imagename = Dir(Fpath & "*.jpg")
On Error Resume Next
For Each sh In ActiveSheet.Shapes
If sh.Type = 13 Or sh.Type = 7 Then
Call sh.Delete
End If
Next
'Open MCU sheet to paste BT Logo
wbk.Worksheets("MCU").Activate
Range("F50").Select
Set p = ActiveSheet.Pictures.insert(Imagename)
p.ShapeRange.LockAspectRatio = msoTrue 'Width and Height are in points (1/72 inch)
Ha = 3 / (p.Height / 72)
Wa = 5 / (p.Width / 72)
If Ha < Wa Then
a = Ha
Else
a = Wa
End If
p.Width = p.Width * a
p.Height = p.Height * a
'Open Summary sheet to paste BT Logo
wbk.Worksheets("Summry").Activate
Range("W1").Select
Set p = ActiveSheet.Pictures.insert(Imagename)
p.ShapeRange.LockAspectRatio = msoTrue 'Width and Height are in points (1/72 inch)
Ha = 3 / (p.Height / 72)
Wa = 5 / (p.Width / 72)
If Ha < Wa Then
a = Ha
Else
a = Wa
End If
p.Width = p.Width * a
p.Height = p.Height * a
wbk.Save
wbk.Close
End Sub
Attachments
Last edited by a moderator: