Jump to content

How to copy a sheet in the working book from a file of a pattern in Excel?


Baloven
 Share

Recommended Posts

Hello,

How to copy a sheet in the working book from a file of a pattern in Excel?

ex.

CODE

$objExcel = ObjCreate("Excel.Application")

With $objExcel

.Visible = 0

.WorkBooks.Open(@ScriptDir&'\Templates\Ticket_rus.xlt', Default, False)

.ActiveWorkbook.Sheets(1).Select()

EndWith

$objTempExcel = ObjCreate("Excel.Application")

With $objTempExcel

.Visible = 0

.WorkBooks.Open(@ScriptDir&'\Templates\Ticket_rus.xlt', Default, False)

.ActiveWorkbook.Sheets(1).Select()

EndWith

$loSheet1 = $objTempExcel.Workbook.Sheets(1)

$loSheet2 = ObjCreate($objExcel.ActiveSheet.Sheets(1))

$loSheet1.Workbook.Copy($loSheet2)

$objExcel = $objExcel.Workbook.Sheets(1)

its d'nt work :P

Link to comment
Share on other sites

Hello,

How to copy a sheet in the working book from a file of a pattern in Excel?

ex.

its d'nt work ;)

I think your problem is opening two instances of the same file. Try opening the workbook, adding a sheet, then copying the active cell range from the source sheet to the new one.

:P

P.S. Even better, there is an $oExcel.ActiveWorkbook.ActiveSheet.Copy method. Makes it all easy.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

All the same it is impossible to make.

It is necessary for me to insert into the open book a copy of a leaf from a pattern (form) with preservation of formatting under condition of if quantity of lines in ListView more than one

CODE

$objExcel = ObjCreate("Excel.Application")

With $oExcel

.Visible = 1

.WorkBooks.Open((@ScriptDir&'\Templates\Ticket_rus.xlt', Default, False)

.ActiveWorkbook.Sheets(1).Select()

EndWith

For $r = 0 to _GUICtrlListViewGetItemCount($ListView)

$a_Item = _GUICtrlListViewGetItemTextArray ($ListView, $r)

If $r <> 0 Then ;Addition of a leaf in the book from an initial pattern

;..... So does not work

$oTempExcel = ObjCreate("Excel.Application")

With $oTempExcel

.Visible = 1

.WorkBooks.Open(@ScriptDir & '\Templates\Ticket_rus.xlt', Default, False)

.ActiveWorkbook.Activate

.ActiveWorkbook.Sheets("Sheet1").Copy

EndWith

$SheetName = 'Sheet' & $r + 1

$objExcel.ActiveWorkBook.WorkSheets.Add.Activate

$objExcel.ActiveSheet.Name = $SheetName

$objExcel.ActiveWorkBook.WorkSheets.Paste

$$oTempExcel.Application.DisplayAlerts = True

$$oTempExcel.Application.ScreenUpdating = True

$oTempExcel.Quit

;.....

EndIf

.....

Filling of the form

....

Next

PS Script write on MS Excel 2003 Edited by Baloven
Link to comment
Share on other sites

I already simply do not know what to do...

In the Help on VBA -

CODE
Worksheets ("Sheet1").Copy After: = Worksheets ("Sheet3")

but if this record to write down in AI

$oTempExcel.ActiveSheet.Sheets(1).Copy After: = $objExcel.ActiveWorkbook.sheets(2)oÝ÷ Û«yÇ¢½æ¦ËZê³)ík§v'í¡Ê)É«­¢+ØÀÌØí½QµÁ᰹ѥÙM¡Ð¹M¡ÑÌ Ä¤¹
½Áä
that we receive copy a leaf in the separate (third) book...

HOW TO DO???: (

HELP.....

Edited by Baloven
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...