Jump to content
Sign in to follow this  
Malkavian99

Autoit program using Excel

Recommended Posts

Malkavian99

Here is what I have done and I'm not sure how to correct it or stop it.

I have a program that searches drives for particular files and puts them into an Excel spreadsheet. The program starts, opens excel in the background, basically Excel is running as a process but I don't see it on the screen. The program does it's scanning and writes the data to the excel spreadsheet after scanning each drive. Once all drives are scanned it closes the excel file, saves it and kills the Excel process.

If during the scan someone opens the Excel program by double clicking the program icon and a blank sheet appears it actually opens a second Excel process under task manager. This is fine. The program is writing to the one you cannot see and you can see the second one. You can then open an excel file and it still doesn't disturb the first Excel program running.

BUT, you know there always is one..

If during the scan someone opens an Excel file, by double clicking the Excel file itself, it opens the file within the first Excel process in another window/book. This disrupts the program. I know this is a feature of Excel and I'm wondering if there is a way to basically lock the Excel session Autoit opens so that if someone were to double click a file it would not use the first Excel Session and open a second Excel session?

I'm using Excel.au3 to get my excel functions.

Any thoughts would be appreciated. Thanks

Michael

Share this post


Link to post
Share on other sites
czardas

Don't write to the spread sheet until you have collected all the data, or don't write to Excel, but write to a csv file which will open in Excel: so you can still use the program while the script is running. Just a suggestion.

Edited by czardas

Share this post


Link to post
Share on other sites
Malkavian99

Thanks for the information. Here is the problem with holding the information until the end. I have approximately 200 drives to scan and holding the data in an array could get really large.

Michael

Share this post


Link to post
Share on other sites
jchd

Have a look at SQLite functions in AutoIt helpfile. SQLite is a database engine which will hold as much data you need safely and with convenient SQL interface. The DB can be temporary (memory) or permanent (storage-based) and can be accessed by any number of processes.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Malkavian99

I have found the answer or at least the answer that works for my situation.

After opening Excel with with the following line (referencing the Excel.au3 module):

$FF_Excel = _ExcelBookNew(0)

The Excel Object reference is returned to the $FF_Excel variable and the Excel spreadsheet is not viewable by the user, basically running as a hidden process.

I added the following line in my code:

$FF_Excel.Application.IgnoreRemoteRequests = True

This actually changes a parameter in the Excel program. When I double clicked an Excel file to open it a new Excel process was started and that process closed when the second file was closed. My program's Excel process was untouched.

If left as true and the program closes, the user is unable to open Excel files by double clicking the file itself. So I added the following line after the _ExcelBookClose($FF_Excel, 0, 0) line.

$FF_Excel.Application.IgnoreRemoteRequests = False

This set the parameter back in Excel so the user can open Excel file by double clicking the file.

I originally thought I was going to need to modify the Excel.au3 functions, but found that I was able to reference the Excel object directly from my code.

This would be a nice parameter to add in the Excel.au3 function when opening. Default as false, but sometimes you want a little more control over your users and you can set it to true. If anyone knows how to contact to possibly have this added I would like to know.

Thanks

Michael

Edited by Malkavian99

Share this post


Link to post
Share on other sites
Juvigy

I think there was a setting in excel of opening every new file by double clicking as a separate process.Here it is:

My Computer

Tools

Folder Options

File Types

Choose XLS

Go to Advanced

Uncheck "browse in same window" in advanced window.

Then highlight Open

Edit

Make sure in the Action box it says &Open

Make sure in the application used to perform action it says:

"C:Program FilesMicrosoft OfficeOFFICE11EXCEL.EXE" "%1"

Check the box next to use DDE

Remove anything that is in DDE Message box and DDE Application Not Running box.

Make sure the application box says: EXCEL

And in the Topic box it says: System

Although the .IgnoreRemoteRequests seems better solution.

Share this post


Link to post
Share on other sites
Malkavian99

Since I would not have access to everyone's workstation the .IgnoreRemoteRequests is the best option for me in my situation. You just have to remember to set it back to False before closing the Excel Object. If you don't and they try to open an Excel file by double clicking it, they will receive an error.

Michael

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
    • nooneclose
      By nooneclose
      I need to perform a subtotal in excel and I would like to automate this process using Autoit if possible like always any and all help will be greatly appreciated. 
      I can not find a good example but the two from Microsoft. Here is one of the two from msdn.microsoft.com/en-us/vba/excel-vba/articles/range-subtotal-method-excel
      I do not really understand how to translate this into AutoIt, but I gave it a try and here is what I have.
      $OpenRange      = "A1:E200" $xlSum          = -4157 $Added_Array[2] = [2, 3] $OpenRange.Subtotal("B1", $xlSum, $Added_Array, True, False, True) I just need to perform a subtotal on a range based on a header called department, and then perform a sum on the results.
    • nooneclose
      By nooneclose
      How to use _Excel_RangeSort to sort my excel file by three different headers Column A1, B1, and C1 have headers on which I want to sort by. The headers on which I want to sort are department, employee type, and name.
      I still really new to AutoIt so I do not actually know how to properly start this line or lines of code, to be honest. The example code is the best I can do.
      _Excel_RangeSort($OpenWorkbook, Default, "A1:C1", "1:1", $xlDescending, Default, $xlYes, Default, $xlSortRows) I just need to sort by those three headers in that order of department, employee type, and name, plus in descending order.
       
      any and all help would be greatly appreciated.  Thank you!
    • Daniza
      By Daniza
      It works fine on my Excel 2007, but after I Emailed My Area Manager he told me after he Enable Macro Security nothing happen's, can someone test this to run on Excel 2016? My AM can't provide me more information 

      Thank You in Advance,
      Please see attachment.
      <snip>
    • tuffgong
      By tuffgong
      Good morning. I have a system I am trying to automate that works like this: user fills a column in an Excel spreadsheet with values they would like printed and saves it to a folder on their desktop, they start the script and it formats their data into a text file (adding a prefix) and sends the text file as a .bch file where it needs to go. This is working:
      #include <Array.au3> #include <Excel.au3> #include <File.au3> #include <MsgBoxConstants.au3> Global $sSTCArray Global $sFilename = @DesktopDir & "\Labels\print.txt" Global $sWorkbook = @DesktopDir & "\Labels\Labels.xlsx" Global $oExcel = _Excel_Open(False,False,False,False,True) barcodePrint() Func barcodePrint() $Read = _Excel_BookOpen($oExcel, $sWorkbook, True, False, Default, Default, Default) FileOpen($sFilename, $FO_OVERWRITE) ;Global $oWorkbook = _Excel_BookAttach($oExcel) Global $sSTCArray = _Excel_RangeRead($Read) For $i = 0 to UBound($sSTCArray, 1) - 1 FileWriteLine($sFilename, "!StaticShelving1x3_ZPL," & $sSTCArray[$i]) Next _Excel_Close($oExcel) FileMove($sFilename, "***file path***\print.bch") EndFunc However, it only works if the user first formats the spreadsheet to text. I want to automate that. From what I have read it appears AutoIt does not like formatting cells that already have values. True? Can I pull the values from an un-formatted (default GENERAL format) spreadsheet and go straight to my text file? I have also considered opening a second spreadsheet, formatting it, and copying the values over. Like this:
        
      Global $sPrefix Global $oPath Global $sSTCArray Global $sFilename = @DesktopDir & "\Labels\print.txt" Global $sWorkbook = @DesktopDir & "\Labels\Labels.xlsx" Global $oExcel = _Excel_Open(False,False,False,False,True) Global $aArray Global $bExcel _Excel_BookNew($bExcel) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $aArray = IniReadSection("***File path***\barcode.ini", "stc/rvt/mgm") $sPrefix = $aArray[1][1] $oPath = $aArray[2][1] barcodePrint() EndSwitch WEnd Func barcodePrint() $oWorkbook = _Excel_BookOpen($bExcel, @DesktopDir & "\Labels\print.xlsx") $oWorkbook.ActiveSheet.Columns("A").NumberFormat = "@" Local $Read = _Excel_BookOpen($oExcel, $sWorkbook, True, False, Default, Default, Default) $oCopy = _Excel_RangeRead($sWorkbook) _Excel_RangeWrite($oWorkbook, Default, $oCopy) FileOpen($sFilename, $FO_OVERWRITE) $sSTCArray = _Excel_RangeRead($Read,"Default","Default",3) ;_ArrayDisplay($sSTCArray) For $i = 0 to UBound($sSTCArray, 1) - 1 FileWriteLine($sFilename, $sPrefix & $sSTCArray[$i]) Next _Excel_Close($oExcel) ;FileMove($sFilename, $oPath) Exit EndFunc This does not like the formatting of $oWorkbook: "Variable must be of type 'Object'".  Do I need this second sheet? If so, how can I format it? Is there a better way to get the Excel values into a .txt file? Any ideas would be appreciated. Thanks!
×