INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

error in code

error in code

(OP)
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

RE: error in code

Try:
xlWB.Sheets("template").Copy After:=xlWB.Sheets(xlWb.Sheets.count)

combo

RE: error in code

(OP)
Very good Combo !!!
It works perfectly.

Thank you very much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close