Jump to content

Open Excel file (2007) and Enable macro


Recommended Posts

Hi,

copied from a 'Juvigy' post, if you want to run the macro.

For macro security settings the link from @exodius should help.

Try:

$oExcel = ObjCreate("Excel.Application") ;crete excel object
$oExcel.WorkBooks.Open($FileName) ;open desired file containing the macro
$oExcel.Run("Macro1") ;run the macro

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

hey guys im getting some strange things with excel, when i run _ExcelBookAttach from the latest offical build, i have an excel.exe process appear for a split second in my task manager, i think this causes the @error to return incorrectly. if i change bookattach method to FileName, it no longer causes the .exe to open. so i'm forced to use filename to have the error return correctly.

i want to use the $oExcel.Run("") macro method mentioned above, but it only seems to work for me with the returned obj from _ExcelBookOpen, the returned obj from _ExcelBookAttach does not let me use .Run, any ideas?

#include <Excel.au3>

Global $filename = "test1.xls"
Global $filepath = "C:\Documents and Settings\Administrator\Desktop\test1.xls"

$oExcel = _ExcelBookAttach($filename, "FileName")
If $oExcel = 0 Then
    $oExcel = _ExcelBookOpen($filepath, 1)
EndIf

_ExcelWriteCell($oExcel, "abc", 2, 2)
$oExcel.Run("TestMacro")
Edited by laffo16
Link to comment
Share on other sites

I didnt know about this command when I wrote my code for something similar so I just used the normal Excel Open Sheet commands and the a Send command to run the macro from inside excel, you have to assign the macro a shortcut first though ;-)

...in case you cant get it to work the other way.

Link to comment
Share on other sites

hey guys im getting some strange things with excel, when i run _ExcelBookAttach from the latest offical build, i have an excel.exe process appear for a split second in my task manager, i think this causes the @error to return incorrectly. if i change bookattach method to FileName, it no longer causes the .exe to open. so i'm forced to use filename to have the error return correctly.

i want to use the $oExcel.Run("") macro method mentioned above, but it only seems to work for me with the returned obj from _ExcelBookOpen, the returned obj from _ExcelBookAttach does not let me use .Run, any ideas?

#include <Excel.au3>

Global $filename = "test1.xls"
Global $filepath = "C:\Documents and Settings\Administrator\Desktop\test1.xls"

$oExcel = _ExcelBookAttach($filename, "FileName")
If $oExcel = 0 Then
    $oExcel = _ExcelBookOpen($filepath, 1)
EndIf

_ExcelWriteCell($oExcel, "abc", 2, 2)
$oExcel.Run("TestMacro")

Yeah, It's a good question.

Anybody know how to run the macro, enable the macro in the attached workbook.

Tks,

LVD

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