Jump to content

Open Hiden Excel and stop running


Recommended Posts

Hi there,

I'm new here, I'm really used to program on VBA, and trying to get used with Autoit.

I created an Workbook that hides itself when I open it, and shows only the a userform.

But it flashes the entire excel background for a second when I'm opening it, that's why I'm turning to Autoit.

I wrote this...

"#include <Excel.au3>

$sFilePath1 = @ScriptDir & "\My_WorkBook.xlsm"

$oExcel = _ExcelBookOpen($sFilePath1,0)"

It works perfectly on the opening process, that is... only the userform shows up.

However when I close my WorkBook, the following error appears...

"C:\Program Files (x86)\AutoIt3\Include\Excel.au3 (194) : ==> Variable must be of type "Object".:

For $i = 1 To .ActiveWorkbook.Sheets.Count

For $i = 1 To .ActiveWorkbook^ ERROR"

I just want the Autoit program to open the workbook and stop running.

How do I do that?

Thanks in advance

>>>> Edit:

I've already tried using

"ShellExecute( ...... , @SW_HIDE) "

But the Excel's background still shows up on the screen...

Edited by Sucrilhus
Link to comment
Share on other sites

Your script works fine on my PC (script closes after excel open). I'm thinking there must be some issue with your VBS userform window that is causing AutoIT to stall.

try disabling it for testing to see if you get the same error.

Link to comment
Share on other sites

Billo, Thanks for the reply

You are right!

Without the activation of the userform, my autoit program closes just fine

Is there a way to run worksheet's macros using autoit?

I've tryed putting a hot key on my macro that calls the Userform "Ctrl + Shift + F"

and wrote 2 extra lines on the autoit program....

Send("{Lctrl down}" + "{LShift down}" + "{f}")

Send("{Lctrl up}" + "{LShift up}")

But it didn't work...

Link to comment
Share on other sites

Thank you both,

"Send("^+f")"

Works just fine when I open the workbook not hidden

I mean... by doing this...

#include <Excel.au3>    
$sFilePath1 = @ScriptDir & "\My_WorkBook.xlsm"
$oExcel = _ExcelBookOpen($sFilePath1,1) ;Shows the application
Send("^+f")

... the program opens my workbook and run the macro perfectly...

But when I put to open in hidden state...

#include <Excel.au3>    
$sFilePath1 = @ScriptDir & "\My_WorkBook.xlsm"
$oExcel = _ExcelBookOpen($sFilePath1,0) ;Hides the application
Send("^+f")

... it opens the workbook but doesn't run the macro...

I concluded that because I've made the following test....

The macro assigned "^+f" just writes on cell A1 "I was here" , which was previously empty

Even after running the following program

#include <Excel.au3>    
$sFilePath1 = @ScriptDir & "\My_WorkBook.xlsm"
$oExcel = _ExcelBookOpen($sFilePath1,0)
Send("^+f")
_ExcelBookClose($oExcel) ;Closes Saving changes

...cell A1 remained empty.

Link to comment
Share on other sites

somdcomputerguy,

It's weird, but again , the same problem remains....

#include <Excel.au3>    
$sFilePath1 = @ScriptDir & "\My_WorkBook.xlsm"
$oExcel = _ExcelBookOpen($sFilePath1,1)
ControlSend("Microsoft Excel - My_WorkBook.xlsm","My_WorkBook.xlsm","","^+d")
_ExcelBookClose($oExcel)

Opens my Workbook, activate the macro, save and close

but..

#include <Excel.au3>    
$sFilePath1 = @ScriptDir & "\My_WorkBook.xlsm"
$oExcel = _ExcelBookOpen($sFilePath1,0)
ControlSend("Microsoft Excel - My_WorkBook.xlsm","My_WorkBook.xlsm","","^+d")
_ExcelBookClose($oExcel)

Either doesn't run the macro... or doesn't save the changes....

>>> Edit:

Is there a way to Stop Screen Update for a certain time, like a second?

Therefore I could Freeze Screen Updating... so that short flash of excel's background wouldn't be displayed....

Edited by Sucrilhus
Link to comment
Share on other sites

You can run the macro like this :

#include <Excel.au3>    
$sFilePath1 = @ScriptDir & "\My_WorkBook.xlsm"
$oExcel = _ExcelBookOpen($sFilePath1,0)
$oExcel.Run("Macro1")
$oExcel.ActiveWorkbook.Save
$oExcel.ActiveWorkbook.Close
Link to comment
Share on other sites

You can run the macro like this :

#include <Excel.au3>    
$sFilePath1 = @ScriptDir & "\My_WorkBook.xlsm"
$oExcel = _ExcelBookOpen($sFilePath1,0)
$oExcel.Run("Macro1")
$oExcel.ActiveWorkbook.Save
$oExcel.ActiveWorkbook.Close

Woah Juvigy! ^^

Thanks a lot!

Not only you've solved my problem but also showed me another way to run macros.

Thanks, everything is running just fine now.

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