AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using a value on excel as a flag

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
gha1d



Joined: 10 Feb 2007
Posts: 15
Location: Sl

PostPosted: Sat Feb 10, 2007 2:43 am    Post subject: Using a value on excel as a flag Reply with quote

Need help on below script guys, Please HELP..

Run D:\Geoffrey\Time Test.xls
WinWait, Microsoft Excel - Time Test,
IfWinNotActive, Microsoft Excel - Time Test, , WinActivate, Microsoft Excel - Time Test,
WinWaitActive, Microsoft Excel - Time Test,
Send, {CTRLDOWN}g{CTRLUP}
WinWait, Go To,
IfWinNotActive, Go To, , WinActivate, Go To,
WinWaitActive, Go To,
Send, d1{ENTER}

What i need to know is how to run a program if the above mentioned cell d1 contains a value like 1 or 0,

Eg:
If the cell contains 1, then run c:\my documents\Test.ahk
If the cell contains 0, do nothing
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
DJAnonimo



Joined: 10 Sep 2006
Posts: 157

PostPosted: Sat Feb 10, 2007 3:03 am    Post subject: Reply with quote

No way, its excel file, when you opet it as text its all crypted...

Better open it and retrieve the number, if you have a good PC
it will be fast, about a second Razz
Back to top
View user's profile Send private message MSN Messenger
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Sat Feb 10, 2007 8:43 am    Post subject: Reply with quote

That's what he does...
I understand that you selected the D1 cell and suppose you succeeded. Then Send ^c to copy the value in the cell, and get its value in the Clipboard variable (might need to wait a bit).
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Rabiator



Joined: 17 Apr 2005
Posts: 289
Location: Sauerland

PostPosted: Sat Feb 10, 2007 10:47 am    Post subject: Reply with quote

There is another way to manage it, with an additional vbscript.

With it you don't have to open the excel file at all, therefore it's faster.

To use vbscript, the Windows Script Host has to be activated.
Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Script Host\Settings Enable=1.
Attention please, activating this is often deemed to be a securty risk!

Save the following vbscript e. g. in TEST.VBS.
It reads the cell contents and saves it to RESULT.TXT.
Code:

' VB script, Filename: TEST.VBS
Dim objXL
Dim Var

ExcelFile = "D:\Geoffrey\Time Test.xls"
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objXL = WScript.CreateObject("Excel.Application")
If Fso.FileExists(ExcelFile) Then
  objXL.Workbooks.Open(ExcelFile)
Else
  WScript.Quit
End If

objXL.Range("D1").Select
Var = objXL.Selection.Value
objXL.Application.Quit

Set Data = Fso.OpenTextFile("Result.txt", 8, True)
Data.Write(Var)
Data.Close


With the following ahk script you run the above vbscript, evaluate the result and do further steps. Example:
Code:
FileDelete, Result.txt
RunWait, Test.vbs
FileRead, Cell, Result.txt

If (Cell = 1)
  run, c:\my documents\Test.ahk


__________________________________________
Created with BBCodeWriter 6.6 - the one and only Very Happy
Back to top
View user's profile Send private message
gha1d



Joined: 10 Feb 2007
Posts: 15
Location: Sl

PostPosted: Wed Feb 17, 2010 6:18 am    Post subject: Reply with quote

I forget to thank you for this Rabiator, Good Luck..
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Rabiator



Joined: 17 Apr 2005
Posts: 289
Location: Sauerland

PostPosted: Wed Feb 17, 2010 11:17 pm    Post subject: Reply with quote

Better late than never. Smile
Back to top
View user's profile Send private message
Jeremiah



Joined: 20 Apr 2009
Posts: 797
Location: North Dakota, USA

PostPosted: Thu Feb 18, 2010 12:42 am    Post subject: Reply with quote

Wow. Very helpful. I actually needed something like this. lol. Ironically. Thank you Rabiator.
_________________
-Jeremiah
Back to top
View user's profile Send private message Send e-mail MSN Messenger
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Thu Feb 18, 2010 3:38 am    Post subject: Reply with quote

Helpful indeed Very Happy - here's basically the same thing using AHKL & COM_L, now that we have more options Wink :
Code:
If FileExist( ExcelFile := "D:\Geoffrey\Time Test.xls" ) {
   pxl := COM_CreateObject( "Excel.Application" )
   pxl.WorkBooks.Open( ExcelFile )
   Cell := pxl.Range( "D1" ).Value
   pxl.Quit()
   If ( Cell = 1 )
      Run, C:\My Documents\Test.ahk
}

_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Thu Feb 18, 2010 5:33 am    Post subject: Reply with quote

Code:
FileSelectFile,excel
workbook:=ComObjGet(excel)
if workbook.worksheets(1).range("a1").value = 1
   ; run somepath
workbook.application.quit()

using the latest and greatest http://www.autohotkey.com/forum/viewtopic.php?p=332144#332144

see
http://www.autohotkey.com/forum/viewtopic.php?p=332273#332273

no need for a library just the com based unicode version sean wrote
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group