Import Picture from camera

G

Greg B

I have tried to import a picture from my webcam into a cell in excel. I have
managed to do it manually with no problem but when I recorded the macro
using the recorder it show nothing that I have done.

the device I wish to use in the
Insert - Picture - insert picture from camera or scanner

I have no idea what I use to get this menu option to appear for me

Thanks

Greg B
 
M

mcgurkle

I have tried to import a picture from my webcam into a cell in excel. I have
managed to do it manually with no problem but when I recorded the macro
using the recorder it show nothing that I have done.

the device I wish to use in the
Insert - Picture - insert picture from camera or scanner

I have no idea what I use to get this menu option to appear for me

Thanks

Greg B


Hi Greg,

I cobbled this together quickly, and it seems to work:

Sub ImportPicture()
'Imports a picture to cell A1 of the active worksheet

Dim wb As Workbook
Dim ws As Worksheet
Dim varFileName As Variant
Dim rngImportTo As Range
Dim lngPictureWidth As Long, lngPictureHeight As Long
Dim picPicture As Picture

Set wb = ThisWorkbook
Set ws = wb.ActiveSheet

Set rngImportTo = ws.Range("A1")


varFileName = Application.GetOpenFilename(FileFilter:="GIF
(*.gif), *.gif,JPEG (*.jpg), *.jpg", Title:="Select an Image File ")


If Not varFileName = False Then
Set picPicture =
rngImportTo.Parent.Pictures.Insert(varFileName)

'the next bit resizes the picture so it looks like
it's in the destination cell
'***leave this bit out to just put the picture in the
top left of the sheet****
With picPicture
.Height = rngImportTo_Offset.Height
.Width = rngImportTo.Width
.Left = rngImportTo.Left
.Top = rngImportTo.Top
End With

'*********************************************************************************

End If

End Sub


Just change the cell address in the line "Set rngImportToRange =
ws.Range("A1")" from A1 to whatever you want.
hope this helps

Laura
 
G

Greg B

Thanks for your help

Greg B

mcgurkle said:
Hi Greg,

I cobbled this together quickly, and it seems to work:

Sub ImportPicture()
'Imports a picture to cell A1 of the active worksheet

Dim wb As Workbook
Dim ws As Worksheet
Dim varFileName As Variant
Dim rngImportTo As Range
Dim lngPictureWidth As Long, lngPictureHeight As Long
Dim picPicture As Picture

Set wb = ThisWorkbook
Set ws = wb.ActiveSheet

Set rngImportTo = ws.Range("A1")


varFileName = Application.GetOpenFilename(FileFilter:="GIF
(*.gif), *.gif,JPEG (*.jpg), *.jpg", Title:="Select an Image File ")


If Not varFileName = False Then
Set picPicture =
rngImportTo.Parent.Pictures.Insert(varFileName)

'the next bit resizes the picture so it looks like
it's in the destination cell
'***leave this bit out to just put the picture in the
top left of the sheet****
With picPicture
.Height = rngImportTo_Offset.Height
.Width = rngImportTo.Width
.Left = rngImportTo.Left
.Top = rngImportTo.Top
End With

'*********************************************************************************

End If

End Sub


Just change the cell address in the line "Set rngImportToRange =
ws.Range("A1")" from A1 to whatever you want.
hope this helps

Laura
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top