Jump to content

Recommended Posts

Posted

Question:

I am familiar with creating a new Excel object, and working with it. However, is there a way to use a pre-existing Excel file and open it as a new object, so that I can work with it, as if I just created it?

Example:

I use this often:

$oExcel = ObjCreate("Excel.Application")                   ; Create an Excel ObjectoÝ÷ Ø­Ëaz·Á¬­¢ë¶¬¶©zz+¦§¶Ú^§v~,²&åx(ºWeG­¡§¢jeÈm+0ØhºÖv)àj|§{Ââ殶­sbb33c´fÆUFô÷VâÒ67&DF"fײgV÷C²b3#´W6VÂçÇ2gV÷C°¢b33c¶ôW6VÂÒö&¤7&VFRgV÷C´W6VÂäÆ6FöâgV÷C²Âb33c´fÆUFô÷Vâ²7&VFRâW6VÂö&¦V7Bg&öÒ6fVBW6VÂfÆR

Thanks In Advance.

Posted

Question:

I am familiar with creating a new Excel object, and working with it. However, is there a way to use a pre-existing Excel file and open it as a new object, so that I can work with it, as if I just created it?

Example:

I use this often:

$oExcel = ObjCreate("Excel.Application")                   ; Create an Excel ObjectoÝ÷ Ø­Ëaz·Á¬­¢ë¶¬¶©zz+¦§¶Ú^§v~,²&åx(ºWeG­¡§¢jeÈm+0ØhºÖv)àj|§{Ââ殶­sbb33c´fÆUFô÷VâÒ67&DF"fײgV÷C²b3#´W6VÂçÇ2gV÷C°¢b33c¶ôW6VÂÒö&¤7&VFRgV÷C´W6VÂäÆ6FöâgV÷C²Âb33c´fÆUFô÷Vâ²7&VFRâW6VÂö&¦V7Bg&öÒ6fVBW6VÂfÆR

Thanks In Advance.

You should use the ObjCreate function then use the open method to open an existing workbook. Refer to either/both of these posts: http://www.autoitscript.com/forum/index.ph...02&hl=excel and http://www.autoitscript.com/forum/index.ph...66&hl=excel

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Posted

Here's a UDF I pulled from my UDF collection that will illustrate the process of opening an existing workbook in code:

;===============================================================================
;
; Description:      Opens an existing workbook and returns its object identifier.
; Syntax:           $oExcel = _ExcelBookOpen($sFilePath, $fVisible = 1)
; Parameter(s):     sFilePath - Path and filename of the file to be opened
;                   $fVisible - Flag, whether to show or hide the workbook (0=not visible, 1=visible) (default=1)
;                   $fReadOnly - Flag, whether to open the workbook as read-only (True or False) (default=False)
; Requirement(s):   None
; Return Value(s):  On Success - Returns new object identifier
;                   On Failure - Returns 0 and sets @error on errors:
;                       @error=1 - Specified object does not exist
;                       @error=2 - File does not exist
; Author(s):        SEO <locodarwin at yahoo dot com>
; Note(s):          None
;
;===============================================================================
Func _ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False)
    $oExcel = ObjCreate("Excel.Application")
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If NOT FileExists($sFilePath) Then Return SetError(2, 0, 0)
    If $fVisible > 1 Then $fVisible = 1
    If $fVisible < 0 Then $fVisible = 0
    With $oExcel
        .Visible = $fVisible
        .WorkBooks.Open($sFilePath, Default, $fReadOnly)
        .ActiveWorkbook.Sheets(1).Select()
    EndWith
    Return $oExcel
EndFunc ;==>_ExcelBookOpen

-S

(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

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