take webcam picture from userform

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
I want to create a button that will capture a picture from the webcam on my my laptop. Just a trigger of some sort. I don't want to use the software that came with the camera if at all possible. Is this going to be really difficult? Any idea's?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
ok....this maybe impossible. I've spent my entire morning looking for ways to achieve this.

How about if I use an application that already exists on the pc. Can I shift focus from excel to the other program and send keys "ctrl N" and then return focus back to excel. If so; how do I do that?
 
Upvote 0
I'm probably going to use the third party app idea in my second post
Wish I could find a command line for taking picture
 
Upvote 0
OK... I'm getting closer to solving the mystery of capturing a photo using only vba to control a wia device. I found this code online and it seems to almost work. I could use some help with debugging it from the experts.

Before you run the code; you need to do the following:

make sure you've got the wia reference loaded, I'm using Microsoft windows image acquistion library v2.0. The dll is called wiaaut.dll you can get it at http://www.microsoft.com/downloads/...7a-01b8-4de6-91c2-b7ea32537e29&DisplayLang=en
once you've downloaded it, unzip the file, then copy the wiaaut.dll file and paste it in c:\windows\system32 folder (assuming you've got winxp). then open up your access database, open the form you are building, open the vb code. Go to 'tools' the 'references' then either scroll throught till you 'microsoft windows image acquisition library v2.0' and check it or 'browse' navigate to the system 32 folder and select it that way.​




Code:
On Error GoTo Err_btnTakePicture_click
  Dim tempfile As String
Dim mydevice As WIA.Device
Dim item As WIA.item
Dim imfile As WIA.imagefile
Dim Commondialog1 As WIA.CommonDialog
  'put the path and name for the location of your temp file here.
tempfile = ("c:\filename.jpg")
  'the next 4 lines deletes the old temp file if it exists
Set filesystemobject = CreateObject("Scripting.FileSystemObject")
If filesystemobject.fileExists(tempfile) Then
    Kill (tempfile)
End If
  'the next two lines set up the configuration
Set Commondialog1 = New CommonDialog
Set mydevice = Commondialog1.ShowSelectDevice
  Set item = mydevice.ExecuteCommand(wiaCommandTakePicture) 'instructs the camera to take the picture
Set imfile = item.Transfer 'transfers the picture from the camera
  'this line saves the picture to a specified file
imfile.SaveFile (tempfile)
 'this sets the picture on the form to show the new picture
OLEUnbound1.Picture = (tempfile)

 MsgBox "Picture taken"
 Exit_btnTakePicture_click:
    Set mydevice = Nothing
    Set item = Nothing
    Exit Sub
 Err_btnTakePicture_click:
    MsgBox err.Description, vbOKOnly + vbCritical, "Error Taking Picture"
    Resume Exit_btnTakePicture_click
 End Sub
 
Last edited:
Upvote 0
Nevermind!! It works!! I removed the part:
OLEUnbound1.Picture = (tempfile)

it totally works!! Yeehaw!!!!
 
Upvote 0
ok....Been using the camera code for about 2 weeks now. It's kind of buggy. It works and then for what ever reason; stops working. At that point; I can load another app that uses the camera and see the camera function correctly but am unable to get the camera to function via vba until after the computer reboots. Then the camera works for a number of times until it then; craps out again. I need help debugging this. Anyone have idea's?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,479
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top