13lack13lade Posted September 10, 2013 Share Posted September 10, 2013 (edited) *EDIT* Is it possible for autoit to write changes to an excel spreadsheet you are currently in and those changes take effect whilst still in the spreadsheet? E.G i use a button in excel to run an autoit script to move file then update in excel to Yes or No if the file has been moved. however if i am in the excel file it doesnt work.. only when excel is not open $reports = "\\calypso.au.flitech.net\sqlrepts\" $qafiles = "\\fbnecl3\inzb\Documents\Load Support\Tom\Automation\QA Reports\DATA\" Global $oExcel = _ExcelBookOpen("Q:\Documents\Load Support\Tom\Automation\QA Reports\QA_Tracker.xlsm",0) $staypayold = $reports & "p_staypay" $staypaynew = $qafiles & "p_staypay.xls" $hltcstc1old = $reports & "p_hltcstc1" $hltcstc1new = $qafiles & "p_hltcstc1.xls" ;;;;script If FileExists($staypayold) Then ;looks to see if file path exists _ExcelWriteCell($oExcel, "Yes", 6, 7) ;FileMove($staypayold, $staypaynew,1) ;changes first path to second path Else _ExcelWriteCell($oExcel, "No", 6, 7) EndIf if FileExists($hltcstc1old) then _ExcelWriteCell($oExcel, "Yes", 7, 7) ;FileMove($hltcstc1old, $hltcstc1new,1) ;changes first path to second path Else _ExcelWriteCell($oExcel, "No", 7, 7) EndIf Edited September 10, 2013 by 13lack13lade Link to comment Share on other sites More sharing options...
soonyee91 Posted September 10, 2013 Share Posted September 10, 2013 *EDIT* Is it possible for autoit to write changes to an excel spreadsheet you are currently in and those changes take effect whilst still in the spreadsheet? E.G i use a button in excel to run an autoit script to move file then update in excel to Yes or No if the file has been moved. however if i am in the excel file it doesnt work.. only when excel is not open My suggestion: If you're going to use a button in excel, why not just use vba to do the automation and write back to the cell if got any changes to the files? Anyhow, autoit is possible to perform on your described issue. Link to comment Share on other sites More sharing options...
13lack13lade Posted September 10, 2013 Author Share Posted September 10, 2013 (edited) I started it using autoit it then ran into some issues so coded some vba but now i see would of been alot easier all in VBA. *am coding it in VBA now* For future reference though ; How do you get excel to update from autoit while the spreadsheet is already open? does the excel file need to be shared? Edited September 10, 2013 by 13lack13lade Link to comment Share on other sites More sharing options...
soonyee91 Posted September 11, 2013 Share Posted September 11, 2013 How do you get excel to update from autoit while the spreadsheet is already open? does the excel file need to be shared? Can you explain in details? What do you want to achieve? If you can do it in vba, definitely you can convert it to autoit language( vice versa) or can you describe the process that you are going to perform? it will be easier for me to understand Link to comment Share on other sites More sharing options...
13lack13lade Posted September 11, 2013 Author Share Posted September 11, 2013 I have created an excel file that contains QA Reports - so there is columns for when it was last run, and changing the status column to RAN however here lies the dilemma. So they press a button in Excel to run another macro (half vba half autoit) and then i want autoit to change 2 cells as per above ^ However autoit only opens excel in read only (opens another excel) where i just want the already open spread sheet to change.. Link to comment Share on other sites More sharing options...
soonyee91 Posted September 11, 2013 Share Posted September 11, 2013 (edited) Oh, I think I get your points now. So, let me summarize it: 1. You have already opened the excel files and then click on the macro to perform something. 2. Then you have autoit to perform your other function. 3. Autoit fails because it open in read only mode. (Am I right?) The reason that autoit is open the excel in read mode is because of the way you code it. (Put your code here for me to know the specific cause) The solution is you obtain com object reference from your open excel then only perform your code. The function you should look into is ObjGet (more details can be found in helpfile). Edited September 11, 2013 by soonyee91 Link to comment Share on other sites More sharing options...
DW1 Posted September 11, 2013 Share Posted September 11, 2013 To add to what soonyee91 is saying, you are looking for _ExcelBookAttach() instead of _ExcelBookOpen(). AutoIt3 Online Help Link to comment Share on other sites More sharing options...
water Posted September 11, 2013 Share Posted September 11, 2013 And make sure that the user doesn't edit a cell while you try to write to a cell from AutoIt. The script will crash. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
13lack13lade Posted September 12, 2013 Author Share Posted September 12, 2013 (edited) wow guys good info, Okay so i have been looking at ObjGet & _ExcelBookAttach - _ExcelBookAttach seems to be easier to understand but i have one question... Because my $oExcel is being used in my script, yet i need to keep the $team variable that is in the same func as $oExcel what is a way to get around this?? am i able to just add this into the same function?? or am i able to just change the value of $oExcel? $oExcel1 = _ExcelBookAttach("Filepath") _ExcelWriteCell($oExcel1, $team, row, column) Edited September 12, 2013 by 13lack13lade Link to comment Share on other sites More sharing options...
soonyee91 Posted September 12, 2013 Share Posted September 12, 2013 You'll have to choose which variable you would like to use. (Since the function is the same) *Looks like you haven't fully understand why _ExcelbookAttach is needed in this situation. (This function will return the object pointing to your active workbook). The returned variable is needed for other function such as _excelwritecell, & etc You can look at the help file for more clarification Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now