Jump to content

Excel file with AutoITScript


Recommended Posts

Hello, Good Day Guys ^_^

I made a simple stock request for our restaurant store and I want to use AutoIT before opening the file, can I compile them together so I can hide my excel file from the user?

Thaks to 232showtime for helping me using vlookup I appreciate it. :P

 

Edited by Daniza
Link to comment
Share on other sites

  • Moderators

Look at FileInstall to include the excel file with the script. When the script runs you can output to a temp directory, then delete when finished.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

5 hours ago, JLogan3o13 said:

Look at FileInstall to include the excel file with the script. When the script runs you can output to a temp directory, then delete when finished.

FileInstall("C:\Documents and Settings\MPC\Desktop\[UPDATED]Standard Stock Requistion 06122018 - 06152018.xlsm", @TempDir & "\[UPDATED]Standard Stock Requistion 06122018 - 06152018.xlsm", 1)

$FileName =  @TempDir & "\[UPDATED]Standard Stock Requistion 06122018 - 06152018.xlsm"
$oExcelDoc = ObjCreate("Excel.Application")
$oExcelDoc.AutomationSecurity = 1 
$oExcelDoc.Visible = 1 
$oExcelDoc.WorkBooks.Open($FileName)

Thanks Sir @JLogan3o13 for FileInstall, I try to search and I come up with this, open file then make sure Macro is enable.

My problem was how to delete the File from the TempDir after they close the File.

I tried to make a  Workbook_BeforeClose event on Excel but does'nt work (Maybe because cannot delete a open file)

Sub Delete()
On Error Resume Next
aFile = Environ("temp") & "\[UPDATED]Standard Stock Requistion 06122018 - 06152018.xlsm"
Kill aFile
' Make sure it actually got deleted.
End Sub

Any suggestion Thanks ^_^

Edited by Daniza
Link to comment
Share on other sites

You could use the AutoIt script to wait for this event and then delete the Excel file.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

As you use AutoIt to open the Excel workbook you could use the returned object to wait for the close event (untested):

#include <Excel.au3>

$sFileName =  @TempDir & "\[UPDATED]Standard Stock Requistion 06122018 - 06152018.xlsm"
FileInstall("C:\Documents and Settings\MPC\Desktop\[UPDATED]Standard Stock Requistion 06122018 - 06152018.xlsm", $sFileName, 1)
$oExcel = _Excel_Open(False) ; Open Excel invisible
$oExcel.AutomationSecurity = 1 
$oWorkbook = _Excel_BookOpen($oExcel, $sFileName)
ObjEvent($oWorkbook, "Workbook_")
$bExit = False
While 1 ; Wait until the workbook gets closed
    Sleep(10)
    If $bExit Then 
        Sleep(500) ; Make sure that Excel has closed
        FileDelete($sFileName)
        Exit
    EndIf
WEnd 

Func WorkBook_BeforeClose($bCancel)
    $bExit = True
EndFunc

 

Edited by water
Fixed typo

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Hello, @water thanks for the Script you made i changed it a little bit Excel_Opn to Excel Open then False to True it Works fine, but I see one problem after file opened if you activate some stuff like notedpad or use alt+tab file excel will stop working and you need to force close it on task manager.

It works fine if you do open>choose form>click, then your free to shift to other stuffs but if you do is open> shift to other stuff then try to go back excel then issue come up. Sorry for my bad English.

 

Edited by Daniza
Link to comment
Share on other sites

I can't imagine that the problem gets caused by the AutoIt script as it does not automate the GUI (and hence might interfere with other programs).
Can you test with another Excel workbook that dos not run a macro?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Hello @water Upon Observing the code really work's but in a invincible mode, I try to tweak the code put

$oExcel = _Excel_Open(True)

After _Excel_BookOpen then it fix the issue :)

#include <Excel.au3>

$sFileName =  @TempDir & "\[UPDATED]Standard Stock Requistion 06122018 - 06152018.xlsm"
FileInstall("C:\Documents and Settings\MPC\Desktop\[UPDATED]Standard Stock Requistion 06122018 - 06152018.xlsm", $sFileName, 1)
$oExcel = _Excel_Open(False) ; Open Excel invisible
$oExcel.AutomationSecurity = 1
$oWorkbook = _Excel_BookOpen($oExcel, $sFileName)
$oExcel = _Excel_Open(True)
ObjEvent($oWorkbook, "Workbook_")
$bExit = False

While 1 ; Wait until the workbook gets closed
    Sleep(10)
    If $bExit Then
        Sleep(500) ; Make sure that Excel has closed
        FileDelete($sFileName)
        Exit
    EndIf
WEnd

Func WorkBook_BeforeClose($bCancel)
    $bExit = True
EndFunc

 

Thank you for your time @water ;)

Closed..

Edited by Daniza
Link to comment
Share on other sites

Glad you got it working :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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