Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error in code

Status
Not open for further replies.

wmbb

Technical User
Jul 17, 2005
320
NL
Who can help me solving the error in the code below...

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
 
Try:
[tt]xlWB.Sheets("template").Copy After:=xlWB.Sheets(xlWb.Sheets.count)[/tt]

combo
 
Very good Combo !!!
It works perfectly.

Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top