Jump to content
Sign in to follow this  
13lack13lade

FileExists then _ExcelWriteCell

Recommended Posts

13lack13lade

*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 by 13lack13lade

Share this post


Link to post
Share on other sites
soonyee91

 

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

Share this post


Link to post
Share on other sites
13lack13lade

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 by 13lack13lade

Share this post


Link to post
Share on other sites
soonyee91

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

Share this post


Link to post
Share on other sites
13lack13lade

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

Share this post


Link to post
Share on other sites
soonyee91

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 by soonyee91

Share this post


Link to post
Share on other sites
DW1

To add to what soonyee91 is saying, you are looking for _ExcelBookAttach() instead of _ExcelBookOpen().

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
13lack13lade

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 by 13lack13lade

Share this post


Link to post
Share on other sites
soonyee91

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

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  

×