Hi All,
I have been lurking around for an answer but haven't been able to find one for my issue. I am making a macro in Excel that will compile files into a larger file. These files to be compiled also have images in specific boxes that I haven't been able to get to come over. I would select all objects but I need every object Except the first one in each sheet i'm pasting from. I'm kind of new at using VBA and would appreciate any and all help. Here's my code:
I have been lurking around for an answer but haven't been able to find one for my issue. I am making a macro in Excel that will compile files into a larger file. These files to be compiled also have images in specific boxes that I haven't been able to get to come over. I would select all objects but I need every object Except the first one in each sheet i'm pasting from. I'm kind of new at using VBA and would appreciate any and all help. Here's my code:
Code:
Private Sub btnStitchData_Click()
Dim dsh As Worksheet
Dim sh As Worksheet
Dim wb As Workbook
Dim I As Integer
Dim n As Long
Dim blnCountingInit As Boolean
Dim blnShapeC As Boolean
Dim fso As New FileSystemObject
Dim fo As Folder
Dim x As File
Application.DisplayAlerts = False
Set fo = fso.GetFolder("C:\Users\PCCSa\Documents\PCC\Workbooks\Compiler")
Set dsh = ThisWorkbook.Sheets("Compile Test")
For Each x In fo.Files
Set wb = Workbooks.Open(x.Path)
Set sh = wb.Sheets("Invoice")
If blnCountingInit = False Then
n = dsh.Range("A" & Application.Rows.Count).End(xlUp).Row
sh.UsedRange.Copy
dsh.Range("A" & n).PasteSpecial xlPasteAllExceptBorders
blnCountingInit = True
'This part is giving me the most issues. Stuck here because of runtime error 1004
If blnShapeC = False Then
sh.Shapes.Range(Array("Picture 2", sh.Shapes.Count)).Select
Selection.Copy
dsh.Range("Z16" & n).PasteSpecial xlPasteAllMergingConditionalFormats
End If
Else
sh.Range("A15").Select
sh.Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
sh.UsedRange.Copy
dsh.Range("A" & n + 1).PasteSpecial xlPasteAllExceptBorders
End If
wb.Close False
Next
End Sub