Jump to content

Copy Excel worksheet


Tonych
 Share

Recommended Posts

I have a Excel macro:

n = 2

if t > 25 Then

For i = 1 To Int(t / 25)

Sheets(2).Select

Sheets(2).Copy After:=Sheets(n)

n = n + 1

Sheets(n).Select

Sheets(n).Name = "Sheet" & CStr(n)

Next i

End If

There is a form in Sheet2, I need to copy it so that I can put 25 datas in every worksheet.

I want to make it in AutoIt, please anyone could give me some advice! Thanks in advance!

Link to comment
Share on other sites

  • 1 month later...

Thanks for you concern! I am sorry I did not tell it clearly. The main problem is that I want to translate the VBA macro:

Sheets(2).Copy After:=Sheets(2) into AutoIt. Thanks in advance!

Tonych, try use positional notation of argument list:

Worksheet.Copy(Before, After)

and «Default» AutoIt-keyword for optional argument.

Example code:

Local $objExcel
Local $objWorkbook
Local $objWorksheet

$objExcel = ObjCreate("Excel.Application")
$objExcel.Visible = True
$objWorkbook = $objExcel.Workbooks.Add()
$objWorksheet = $objWorkbook.Worksheets(1)

; Mark this worksheet by text
$objWorksheet.Cells(1,1).Value = "Example"
$objWorksheet.Name = "Example"

; Add some worksheets
$objWorkbook.Worksheets.Add
$objWorkbook.Worksheets.Add
$objWorkbook.Worksheets.Add
$objWorkbook.Worksheets.Add
$objWorkbook.Worksheets.Add
$objWorkbook.Worksheets.Add

; Copy this worksheet
$objWorksheet.Copy(Default, $objWorkbook.Worksheets(2))
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...