Who can help me solving the error in the code below...
I get an error in the command
Run time error : '1004'
Method 'Range' of 'object' Global Failed
Code:
Sub Start_Excel_Proces()
'Declare file dialog, Excel workbook and application objects
Dim fd As FileDialog
Dim newsheet As Boolean
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet
'Declare the used vars and constants
Dim i As Integer
Dim LR As Integer
Dim LC As Integer
' select excel-file
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Title = "Selecting Excel Result File"
fd.InitialFileName = ExcelResultDir
fd.InitialView = msoFileDialogViewList
fd.Filters.Clear
fd.Filters.Add "Excel-files", "*.xls*"
fd.FilterIndex = 1
fd.ButtonName = "Choose &This file"
If fd.Show <> -1 Then
MsgBox "Macro stopped without selecting a Excel Result File"
GoTo labelend
End If
Set xlApp = New Excel.Application
Set xlWB = xlApp.Workbooks.Open(fd.SelectedItems(1))
newsheet = True
For Each xlWS In xlWB.Worksheets
If xlWS.Name = Customer Then
xlWS.Activate
newsheet = False
Exit For
End If
Next
If newsheet Then
xlWB.Sheets("template").Visible = xlSheetVisible
xlWB.Sheets("template").Copy After:=xlWB.Sheets(Sheets.count)
xlWB.Sheets("template").Visible = xlSheetVeryHidden
xlWB.Sheets(Sheets.count).Name = Customer
xlWB.Sheets(Customer).Activate
End If
LR = lastrow(xlWB.Sheets(Customer), 1)
xlWB.Sheets(Customer).Cells(LR + 1, 1).Value = LIMSinfoArray(1)
xlWB.Sheets(Customer).Cells(LR + 1, 2).Value = OrderdataArray(1)
xlWB.Sheets(Customer).Cells(LR + 1, 3).Value = OrderdataArray(3)
xlWB.Sheets(Customer).Cells(LR + 1, 4).Value = OrderdataArray(2)
xlWB.Sheets(Customer).Cells(LR + 1, 5).Value = NCdata(1)
xlWB.Sheets(Customer).Cells(LR + 1, 6).Value = NCdata(2)
labelend:
xlWB.Close
xlApp.Quit
Set xlApp = Nothing
Set xlWB = Nothing
Set xlWS = Nothing
End Sub
I get an error in the command
Code:
xlWB.Sheets("template").Copy After:=xlWB.Sheets(Sheets.count)
Run time error : '1004'
Method 'Range' of 'object' Global Failed