StuartHall
New Member
- Joined
- Sep 30, 2013
- Messages
- 35
I'm building a consolidation workbook that imports two worksheets from several different workbooks. One sheet is called "Summary", one is called "E-video." Every workbook has a "Summary" sheet, but not every workbook has an "E-video".
My problem is that when I use On Error Resume Next (in order to skip past the workbooks that do not contain an E-Video sheet), VBA is treating all subsequent workbooks the same, only importing Summary sheets and not importing ANY E-Video sheets.
Does anyone have a solution?
My problem is that when I use On Error Resume Next (in order to skip past the workbooks that do not contain an E-Video sheet), VBA is treating all subsequent workbooks the same, only importing Summary sheets and not importing ANY E-Video sheets.
Does anyone have a solution?
Rich (BB code):
Sub ManualStudiesConsolidation()
Dim Filter As String, Title As String, msg As String
Dim i As Integer, FilterIndex As Integer
Dim Filename As Variant
' File filters
Filter = "Excel Files (*.xlsm),*.xlsm," & _
"All Files (*.*),*.*"
' Default filter to *.*
FilterIndex = 3
' Set Dialog Caption
Title = "Select File(s) to Open"
' Select Start Drive & Path
ChDrive ("J")
ChDir Sheets("Main").Range("f7").Value
With Application
' Set File Name Array to selected Files (allow multiple)
Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
' Reset Start Drive/Path
ChDrive Left(.DefaultFilePath, 1)
ChDir (.DefaultFilePath)
End With
' Exit on Cancel
If Not IsArray(Filename) Then
MsgBox "No file was selected"
Worksheets(Worksheets("Main").Range("e7").Value & " - Summary").Name = "Sheet2"
Worksheets(Worksheets("Main").Range("e7").Value & " - Video").Name = "Sheet3"
Exit Sub
End If
For i = LBound(Filename) To UBound(Filename)
Application.DisplayAlerts = False
Workbooks.OpenText Filename:= _
Filename(i) _
On Error Resume Next
Sheets("Summary").Select
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Summary").Copy After:=Workbooks("MACRO!.xlsm"). _
Sheets("Sheet3")
Sheets("Summary").Name = "Summary" & Format(i, "0")
Sheets("E-Video").Select
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("E-Video").Copy After:=Workbooks("MACRO!.xlsm"). _
Sheets("Sheet3")
Sheets("E-Video").Name = "E-Video" & Format(i, "0")
Next i
Filename(i).Close SaveChanges:=False
Application.DisplayAlerts = True
Worksheets("Sheet2").Name = Worksheets("Main").Range("e7").Value & " - Summary"
Worksheets("Sheet3").Name = Worksheets("Main").Range("e7").Value & " - Video"
End Sub
Last edited: