Jump to content

_Excel_SheetCopyMove


Recommended Posts

Hi,

I would like to seek for your assistance regarding function "_Excel_SheetCopyMove", I read necessary files, other related topics in forum, and yet I cannot perform the function well. I expect that the selected sheet from Workbook1 should be moved to Workbook2, but nothing happens. Please see my code below, any assistance would be very much appreciated. Thanks.

Func _BE_jnknsSeparateSheet(  )

    ; Local Variables
    Local   $sLogTextFile = @ScriptDir & "\..\Log.txt", _
                $sTestSheetFile, _
                $sDrive, _
                $sDir, _
                $sFileName, _
                $sExtension
    Local    $aFilePath
;~                 $aTestDesign
    Local    $fOldSheet, _
                $fNewSheet
    Local   $hTextFile
    Local    $oExcel, _
                $oBook, _
                $oSheet, _
                $oBookName

    ; Open log text file
    $hTextFile = FileOpen($sLogTextFile, $FO_READ)
    ; Open testsheet
    $sTestSheetFile = FileReadLine($hTextFile,2)
    $sTestSheetFile = StringTrimLeft($sTestSheetFile,20)
    Local $aTestDesign[ ] = [ $sTestSheetFile ]

    $oExcel = _Excel_Open()
    $oBook = _Excel_BookNew( $oExcel, 1 )

    For $i = 0 To UBound ( $aTestDesign, 1 ) - 1
        _PathSplit($aTestDesign[$i], $sDrive, $sDir, $sFileName, $sExtension)
    Next

    MsgBox(0, "", $sDrive & $sDir )

    $oBookName = $sDrive & $sDir & "testFile.xlsx"
    _Excel_BookSaveAs( $oBook, $oBookName, $xlWorkbookDefault, True )
    $sTestSheetFile = _Excel_BookOpen ( $oExcel, $sDrive & $sDir & $sFileName & $sExtension )
    $oBookName = _Excel_BookOpen ( $oExcel, True )
    _Excel_SheetCopyMove ( $sTestSheetFile, "1", $oBookName, False )
    _Excel_BookClose ( $sTestSheetFile )
    _Excel_BookClose ( $oBookName )

EndFunc

 

Link to comment
Share on other sites

Could you please describe the problem and - if not obvious - the solution?
So if someone else in the future hits the same problem he can easily find your post and save some time with the provided solution.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The problem I encountered was the new excel instance I created and used to be the container of sheet to be moved is not an object which is required by the function _Excel_SheetCopyMove.

I  just changed my snippet from

$oBookName = _Excel_BookOpen ( $oExcel, True )

to

$oBookName = _Excel_BookOpen ( $oExcel, oBookName )

Thank you @water for your UDF btw.

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

11 hours ago, CiaronJohn said:

rename the whole workbook

_Excel_BookSaveAs

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

3 hours ago, CiaronJohn said:

I'm sorry

No need to be sorry, we all miss things... Speaking of, have you seen my sanity?

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

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...