How To Program Vba With Surface Camera
Running CommandCam from Excel using VBA
Reader Percy Kumah wrote in with a query about running CommandCam (my free command line prototype capture utility) from MS Access using VBA. Since I don't have Access installed myself, I tried it in Excel instead (also using VBA).
Here's how I did it.
Firstly, I created a simple spreadsheet with a control push and an epitome object:
Then I added a subroutine for the "Have Snapshot" button:
Past the way, if you desire the Shell control to run without opening a console window, merely supercede "vbNormalFocus" with "vbHide" in the lawmaking. I deliberately made the console window visible so that I could come across what was going on while writing the programme, but it works fine if yous go on it hidden.
To go on things simple, I copied the file "CommandCam.exe" (which tin can be downloaded from the CommandCam spider web folio) into the same directory as the Excel file:
When the "Take Snapshot" push button is clicked, the subroutine performs the following steps:
- Before doing annihilation else, the current directory is set to the aforementioned location equally the Excel file. The file "CommandCam.exe" is already in this directory and the file "paradigm.bmp" will also be stored there.
- The "Kill" command is used to delete the file "image.bmp" if it already exists.
- The subroutine then waits until the file "image.bmp" is deleted.
- Once the file "image.bmp" is gone, the subroutine uses the Shell command to run CommandCam. Command line arguments for CommandCam can exist included within the inverted commas if required (e.k. to select a specific photographic camera or include a delay earlier taking the snapshot).
- Once again, we demand to requite CommandCam time to take the photo and store it to a file, so at this point the subroutine simply keeps checking to see if the file exists yet.
- Once the file exists, an additional brusk delay is required to give CommandCam time to cease writing data to the file and close it.
- Finally, the image is loaded from the file into the Film member of the Image1 object (that's the image object on the spreadsheet).
Finally, in example you want to cut and paste the subroutine code, here it is once more:
Private Sub SnapshotButton_Click() Dim RetVal ' Brand sure the current directory is prepare to the i ' where the Excel file is saved ChDir (ActiveWorkbook.Path) ' Kickoff, delete epitome file if nowadays Kill ("image.bmp") ' Now, wait until image file is definitely gone While Dir("paradigm.bmp") > "" Wend ' Capture new epitome RetVal = Shell("CommandCam.exe", vbNormalFocus) ' Wait until image file is definitely there While Dir("image.bmp") = "" Wend ' Brusque delay to let new file finish saving Application.Wait (Now + TimeValue("00:00:01")) ' Load new image into image object on spreadsheet Image1.Picture = LoadPicture("image.bmp") Cease Sub
This entry was posted in Uncategorized and tagged CommandCam, Excel, VBA. Bookmark the permalink.
Source: https://batchloaf.wordpress.com/2013/01/07/running-commandcam-from-excel-using-vba/
Posted by: hallfounds82.blogspot.com
0 Response to "How To Program Vba With Surface Camera"
Post a Comment