I have created a script that is failing in one line and I have looked for the past 6 weeks on why its failing with no results can you please help. The error produced is: Select method of Range class failed (line failure noted in red)
Option Explicit
'Define variables
Dim strPathSrc, strMaskSrc, iSheetSrc, strPathDst, iSheetDst, objExcel, objWorkBookDst, objSheetDst, objShellApp, objFolder, objItems, objItem, objUsedRangeDst, objWorkBookSrc, objSheetSrc, iRowsCount, sSubF, objfso
'Source files folder
strPathSrc = "C:\Testing\"
'Source files filter mask
strMaskSrc = "*.xlsx"
'Source sheet index or name
iSheetSrc = 1
'Destination file
strPathDst = "H:\Results.xlsx"
'Destination sheet index or name
iSheetDst = "Sheet1"
Set objfso = CreateObject("Scripting.FileSystemObject")
'Set up object
Set objExcel = CreateObject("Excel.Application")
'hide sheet viewing
objExcel.Visible = False
'Open excel workbooks
Set objWorkBookDst = objExcel.Workbooks.Open(strPathDst)
'Define sheets
Set objSheetDst = objWorkBookDst.Sheets(iSheetDst)
'Define Shell app
Set objShellApp = CreateObject("Shell.Application")
'Deine folder path
'Set objFolder = objShellApp.NameSpace(strPathSrc)
Set objFolder = objfso.GetFolder(strPathSrc)
'msgbox objFolder
Set sSubF = objFolder.SubFolders
'Set objitems = sSubf.Items()
For each objItem in sSubF
dim sFolder, colFiles, x
Set sFolder = objfso.GetFolder(objitem.path)
Set colFiles = sFolder.files
objExcel.DisplayAlerts = False
For each x in colFiles
Set objWorkBookSrc = objExcel.Workbooks.Open(x.Path)
Set objSheetSrc = objWorkBookSrc.Sheets(iSheetSrc)
GetUsedRange(objSheetSrc).Copy
Set objUsedRangeDst = GetUsedRange(objSheetDst)
iRowsCount = objUsedRangeDst.Rows.Count
objWorkBookDst.Activate
objSheetDst.Cells(iRowsCount + 1, 1).Select 'Failing here
objSheetDst.Paste
objWorkBookDst.Application.CutCopyMode = False
objWorkBookSrc.Close
Next
next
Option Explicit
'Define variables
Dim strPathSrc, strMaskSrc, iSheetSrc, strPathDst, iSheetDst, objExcel, objWorkBookDst, objSheetDst, objShellApp, objFolder, objItems, objItem, objUsedRangeDst, objWorkBookSrc, objSheetSrc, iRowsCount, sSubF, objfso
'Source files folder
strPathSrc = "C:\Testing\"
'Source files filter mask
strMaskSrc = "*.xlsx"
'Source sheet index or name
iSheetSrc = 1
'Destination file
strPathDst = "H:\Results.xlsx"
'Destination sheet index or name
iSheetDst = "Sheet1"
Set objfso = CreateObject("Scripting.FileSystemObject")
'Set up object
Set objExcel = CreateObject("Excel.Application")
'hide sheet viewing
objExcel.Visible = False
'Open excel workbooks
Set objWorkBookDst = objExcel.Workbooks.Open(strPathDst)
'Define sheets
Set objSheetDst = objWorkBookDst.Sheets(iSheetDst)
'Define Shell app
Set objShellApp = CreateObject("Shell.Application")
'Deine folder path
'Set objFolder = objShellApp.NameSpace(strPathSrc)
Set objFolder = objfso.GetFolder(strPathSrc)
'msgbox objFolder
Set sSubF = objFolder.SubFolders
'Set objitems = sSubf.Items()
For each objItem in sSubF
dim sFolder, colFiles, x
Set sFolder = objfso.GetFolder(objitem.path)
Set colFiles = sFolder.files
objExcel.DisplayAlerts = False
For each x in colFiles
Set objWorkBookSrc = objExcel.Workbooks.Open(x.Path)
Set objSheetSrc = objWorkBookSrc.Sheets(iSheetSrc)
GetUsedRange(objSheetSrc).Copy
Set objUsedRangeDst = GetUsedRange(objSheetDst)
iRowsCount = objUsedRangeDst.Rows.Count
objWorkBookDst.Activate
objSheetDst.Cells(iRowsCount + 1, 1).Select 'Failing here
objSheetDst.Paste
objWorkBookDst.Application.CutCopyMode = False
objWorkBookSrc.Close
Next
next