I'm trying to write a copy and paste program that lets the user select which xml files to merge and then in sequence opens up the xml file selected second and paste it into the first selected file (top file in final completed file), opens the xml file selected third and paste it into the xml file selected first ... (until the last file selected had been pasted into the first file selected) and then save the final completed product as a brand new xlsm file with a file name constituting the first and last files pasted onto the very first file opened. But I keep running into either subscript out of range errors or type mismatch errors
Any suggsestions??
Sub Merge()
Dim File As String
Dim AllFiles() As Variant 'Array containing file names to be opened and manipulated
Dim count, test, LastRow As Long 'Count equals number of files stored in Allfiles array, LastRow==equals last row of a sheet for purpose of finding selection area
'codes....
ReDim AllFiles(count)
test = 2
Do While (test <= count)
Windows(AllFiles(test)).Activate 'Subscript out of range error
'codes
Range("LastRow").Select 'subscript out of range error/type mismatch
'codes
ActiveWorkbook.SaveAs Filename:="C:\Allfiles(1)&Allfiles(count)\" & ".xlsm", FileFormat:=52 'save as new .xlsm file with file names of first file opened in allfiles concatenated with last file opened in allfiles. error :type mismatch/subscript out of range

Sub Merge()
Dim File As String
Dim AllFiles() As Variant 'Array containing file names to be opened and manipulated
Dim count, test, LastRow As Long 'Count equals number of files stored in Allfiles array, LastRow==equals last row of a sheet for purpose of finding selection area
'codes....
ReDim AllFiles(count)
test = 2
Do While (test <= count)
Windows(AllFiles(test)).Activate 'Subscript out of range error
'codes
Range("LastRow").Select 'subscript out of range error/type mismatch
'codes
ActiveWorkbook.SaveAs Filename:="C:\Allfiles(1)&Allfiles(count)\" & ".xlsm", FileFormat:=52 'save as new .xlsm file with file names of first file opened in allfiles concatenated with last file opened in allfiles. error :type mismatch/subscript out of range