Hi Everyone,
I have created a macro in excel 2003 to copy contents from another workbook. It is working well. However I am trying to run the same macro in excel 2007 , it is not working. All macros are enabled. Also other macros are running. After testing the macro, I found it the problem is in the opening files to copy. So please help in resolving the issue happening in this code.
'Usage
'Importing data from other workbooks
Sub Importdata()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim sPath As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set wbCodeBook = ThisWorkbook
With Application.FileSearch
.NewSearch
'Change path to suit - here Information Input :B10 contains the path of the excel files
.LookIn = wbCodeBook.Worksheets("Information Input").Range("B10")
.FileType = msoFileTypeAllFiles
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count ' Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
'Importing Data
wbResults.Worksheets("Sheet1").Range("A2:AH10000").Copy
wbCodeBook.Worksheets("Sheet1").Range("A" & wbCodeBook.Worksheets("Data Input").Range("A10001").End(xlUp).Row).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
wbResults.Close SaveChanges:=False
Next lCount
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Bookmarks