Jump to content

Excel SheetCopyMove in Excel.au3 not behaving as I expect..


Go to solution Solved by Nine,

Recommended Posts

Posted (edited)
#include <Excel.au3>

Local $sResultTemplateFilename          = @ScriptDir & "\Test.xls"

;Set up demo workbook
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, $sResultTemplateFilename, Default, True)
_Excel_SheetAdd($oWorkbook, Default, 1, Default, "Template")
$oWorkbook.Sheets("Template").Activate
;All above works fine

;Statement which doesn't work as expected
_Excel_SheetCopyMove($oWorkBook, "Template", $oWorkBook, "Copy", Default, True)

;Expected : Test.xls has two sheets, Template and Copy
;Actual   : Test.xls has Template sheet, Book1.xls has Template sheet

Help, I've been banging my head against a brick wall for days.

What am I doing wrong above? I'm trying to achieve a simple duplication of a Sheet within the same Book, named 'Copy'. What I'm getting is a new book with the sheet 'Template' in it. I've also tried _Excel_SheetCopyMove($oWorkBook, "Template", Default, "Copy", Default, True) which behaves the same way.

Although not shown in the snippet, I check @error and it reports '0' in all cases.

(As an aside, I've just abandoned the process using OpenOffice and LibreOffice, with OOo_Calc.au3,  due to a bug in the chart drawing functionality in that product - several days wasted in that effort! 😉 )

Thanks

John

Edited by g0gcd
Missed a bit..
  • Solution
Posted

Take a look at the example of _Excel_SheetCopyMove.  You are naming the new sheet wrongly ("Copy").  Create new sheet then rename it.

Local $oCopiedSheet = _Excel_SheetCopyMove($oWorkBook, "Template", Default, Default, Default, True)
$oCopiedSheet.Name = "Copy"

 

Posted

@Nine

Thank you for pointing out that which should have been blindingly obvious. I'm guilty of not looking carefully enough and was so bogged down with OpenOffice (which does copy/paste and rename in one step) that I didn't see what was in front of me.

Much appreciated and thanks for your time

John G0GCD

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
  • Recently Browsing   0 members

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