Copy excel sheet

Hi,

I know this issue is posted before but I cannot find the solution.

I want to copy a sheet from an xls file into another. My codes are the following:

tempfile =“c:\wages\temp_wages.xls”

tempxls=Dir$(tempfile)

If tempxls=“” Then

Set tempExcel = Createobject(“Excel.Application”)

Set tempxlBook = tempExcel.Workbooks.Add()

Call tempxlBook.SaveAs(tempfile, -4143, “”, “”, False, False, 1)

Else

Set tempExcel = Createobject(“Excel.Application”)

Set tempxlBook = tempExcel.Workbooks.open(tempfile)

Set tempxlSheet = tempExcel.Worksheets.Add()

Call tempxlBook.Save

End If

Set tempExcel = Getobject(tempfile)

filename = “c:\wages"+Trim(Aempid(w))+”.xls"

xlsfile=Dir$(filename)

Set Excel = Createobject(“Excel.Application”)

Set xlBook = Excel.Workbooks.open(filename)

tempExcel.sheets(1).copy (Excel.sheets(1))

I get the error message “incorrect copy method”. I also tried:

tempExcel.sheets(1).copy Before:=Excel.sheets(1) and

tempExcel.sheets(1).copy (, Excel.sheets(1))

None of them works.

Can anyone help me?

Thank you very much.

Etyien

Subject: copy excel sheet

The problem is that the destination parameter is supposed to be a variant containing a range, not a worksheet.

From the help file:

Syntax 1: Copies the object to the Clipboard. Copies a picture of the point or series to the Clipboard.

Syntax 2: Copies the Range to the specified range or to the Clipboard.

Syntax 3: Copies the sheet to another location in the workbook.

Syntax 1

expression.Copy

Syntax 2

expression.Copy(Destination)

Syntax 3

expression.Copy(Before, After)

expression Required. An expression that returns an object in the Applies To list. To copy an entire chart sheet, use Syntax 3 with the Chart object. To copy only the chart area, use Syntax 1 with the ChartArea object.

Destination Optional Variant. Specifies the new range to which the specified range will be copied. If this argument is omitted, Microsoft Excel copies the range to the Clipboard.

Before Syntax 3: Optional Variant. The sheet before which the copied sheet will be placed. You cannot specify Before if you specify After.

After Optional Variant. The sheet after which the copied sheet will be placed. You cannot specify After if you specify Before.

Remarks

If you don’t specify either Before or After, Microsoft Excel creates a new workbook that contains the copied sheet.