Serving the Quantitative Finance Community

 
User avatar
J
Topic Author
Posts: 1
Joined: November 1st, 2001, 12:53 am

automatically work in VBA

January 28th, 2009, 1:11 am

suppose we want to write a VBA code to do the following thing:if the value in a specific cell is over a specific value, the program will automatically take a screen shot. The user can leave his desktop and does not need to sit in front of his monitor to watch if the value in a specific cell is over a specific value.Which programming can help me finish this task? Do I need an executable file (.exe file) to run the program?
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

automatically work in VBA

January 28th, 2009, 2:48 am

The first task is to trap the value when it happens.That's best done by having a VBA function that simply references the cell as inFunction Record(x as variant)if x...end subNote, I use Variant not double, if this is to trap an "interesting" condition best that you allow for anything to happen."capturing" the screen can be done by BitBlt, but I don't think this is what you want in this case...I suspect you wat to do something like Open "C:\mytest.csv"for each in range Print #1, sheet1.cells(i,j),;",";nextIe dump the values of the sheet to a file.If you just do a screen capture, you're likely to pick up a Bloomberg/Reuters/porn image depending on what the user is looking at...
 
User avatar
J
Topic Author
Posts: 1
Joined: November 1st, 2001, 12:53 am

automatically work in VBA

January 28th, 2009, 3:43 pm

QuoteOriginally posted by: DominicConnorThe first task is to trap the value when it happens.That's best done by having a VBA function that simply references the cell as inFunction Record(x as variant)if x...end subNote, I use Variant not double, if this is to trap an "interesting" condition best that you allow for anything to happen."capturing" the screen can be done by BitBlt, but I don't think this is what you want in this case...I suspect you wat to do something like Open "C:\mytest.csv"for each in range Print #1, sheet1.cells(i,j),;",";nextIe dump the values of the sheet to a file.If you just do a screen capture, you're likely to pick up a Bloomberg/Reuters/porn image depending on what the user is looking at...VBA program need to be activated by an event e.g. clicking a button. Can we activate a VBA program without clicking a button? I want the program automatically take a screen shot without me clicking a button.This program has to be run for 24 hours.
 
User avatar
rmax
Posts: 374
Joined: December 8th, 2005, 9:31 am

automatically work in VBA

January 29th, 2009, 8:58 am

Number of ways to do this.1. Import the Timer from Visual Basic (if available)2. Have the following loopDo If [Condition] Run Code proposed by DFC ' (or use WinAPI to take screen shot if you are feeling like delving into the API) End If Do Events ' this will ensure that the loop doesn't hang your programme and should run BBG feeds etcLoop Until [Condition]3. You could use the timer function on an Access form as a poor mans scheduler. When that fires you run a piece of code in Access that will run the macro in the you Excel sheet. Or move the whole lot to Access4. use another piece of software and not use Excel (VB, C#, Java, C++ Ruby etc etc etc etc)
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

automatically work in VBA

February 1st, 2009, 7:37 pm

VBA lets you do timer eventsSub DominiConnor()Application.OnTime Now + TimeValue("00:00:1"), "DominiConnor"End SubYou tell VBA to call a function in not less than the interval provided, so you can call yourself.
 
User avatar
rmax
Posts: 374
Joined: December 8th, 2005, 9:31 am

automatically work in VBA

February 2nd, 2009, 9:59 am

QuoteOriginally posted by: DominicConnorVBA lets you do timer eventsSub DominiConnor()Application.OnTime Now + TimeValue("00:00:1"), "DominiConnor"End SubYou tell VBA to call a function in not less than the interval provided, so you can call yourself.learn a new thing everday...
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

automatically work in VBA

February 2nd, 2009, 6:22 pm

"learn a new thing everday.."Glad to be of help
 
User avatar
dirtydroog
Posts: 0
Joined: July 12th, 2007, 6:32 pm

automatically work in VBA

February 8th, 2009, 8:35 pm

QuoteOriginally posted by: DominicConnorThe first task is to trap the value when it happens.That's best done by having a VBA function that simply references the cell as inFunction Record(x as variant)if x...end subNote, I use Variant not double, if this is to trap an "interesting" condition best that you allow for anything to happen."capturing" the screen can be done by BitBlt, but I don't think this is what you want in this case...I suspect you wat to do something like Open "C:\mytest.csv"for each in range Print #1, sheet1.cells(i,j),;",";nextIe dump the values of the sheet to a file.If you just do a screen capture, you're likely to pick up a Bloomberg/Reuters/porn image depending on what the user is looking at...BitBlt is a bit overkill, no? Maybe it would be possible to fake a 'PrintScreen' button press and then dump the clipboard contents to file?