PC Review


Reply
Thread Tools Rate Thread

VBA insert a photo

 
 
azidrane
Guest
Posts: n/a
 
      15th Mar 2006
I am inserting a photo into a worksheet and sizing it to a specific
range when a name is chosen from a list validated cell. I am using the
following code:

*********************************
Dim RepPhoto As Picture
Dim CurrentWorksheet As Worksheet
Dim RepPhotoFileName As Variant
Dim strFirstName As Variant
Dim strLastName As Variant

Set CurrentWorksheet = ActiveSheet

'Get the FIRST NAME of the full name stored in the cell H5
strFirstName = Trim(Right(Range("H5"), Len(Range("H5")) - InStr(1,
Range("H5"), ",", vbTextCompare) - 1))

''Get the LAST NAME of the full name stored in the cell H5
strLastName = Trim(Left(Range("H5"), InStr(1, Range("H5"), ",",
vbTextCompare) - 1))

'Store this as a file name
RepPhotoFileName = "\\Networkdrive\photos\" & strFirstName & " " &
strLastName & ".jpg"

'Insert the photo into the worksheet
Set RepPhoto = CurrentWorksheet.Pictures.Insert(RepPhotoFileName)

'Resize the photo to this merged cell (B4:C10)
With Range("B4:C10")
RepPhoto.Top = .Top
RepPhoto.Width = .Width
RepPhoto.Height = .Height
RepPhoto.Left = .Left
RepPhoto.Placement = xlMoveAndSize
End With

*********************************

This works, UNTIL I share the workbook....
When it shared we get this error:
"Runtime error: 1004"
"Unable to get the Insert property of the Picture Class"

Cannot figure it out...


Also, does anyone know how to delete the photo from the work sheet when
you choose a different name?

There are no other pic's on the sheet so maybe a with statement?

Cheers!

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      15th Mar 2006
If you look at excel's help for "Features that are unavailable in shared
workbooks", you'll see that inserting pictures is something you can't do.

Maybe you could put all the picutures on a sheet (hide that sheet) and then copy
it to the location you want.

Or just put all the pictures in that location and hide all of them--then use
code to just show the one you want.

J.E. McGimpsey has a routine that hides/unhides pictures based on the value of a
cell.
http://www.mcgimpsey.com/excel/lookuppics.html

You might be able to use some of it.

azidrane wrote:
>
> I am inserting a photo into a worksheet and sizing it to a specific
> range when a name is chosen from a list validated cell. I am using the
> following code:
>
> *********************************
> Dim RepPhoto As Picture
> Dim CurrentWorksheet As Worksheet
> Dim RepPhotoFileName As Variant
> Dim strFirstName As Variant
> Dim strLastName As Variant
>
> Set CurrentWorksheet = ActiveSheet
>
> 'Get the FIRST NAME of the full name stored in the cell H5
> strFirstName = Trim(Right(Range("H5"), Len(Range("H5")) - InStr(1,
> Range("H5"), ",", vbTextCompare) - 1))
>
> ''Get the LAST NAME of the full name stored in the cell H5
> strLastName = Trim(Left(Range("H5"), InStr(1, Range("H5"), ",",
> vbTextCompare) - 1))
>
> 'Store this as a file name
> RepPhotoFileName = "\\Networkdrive\photos\" & strFirstName & " " &
> strLastName & ".jpg"
>
> 'Insert the photo into the worksheet
> Set RepPhoto = CurrentWorksheet.Pictures.Insert(RepPhotoFileName)
>
> 'Resize the photo to this merged cell (B4:C10)
> With Range("B4:C10")
> RepPhoto.Top = .Top
> RepPhoto.Width = .Width
> RepPhoto.Height = .Height
> RepPhoto.Left = .Left
> RepPhoto.Placement = xlMoveAndSize
> End With
>
> *********************************
>
> This works, UNTIL I share the workbook....
> When it shared we get this error:
> "Runtime error: 1004"
> "Unable to get the Insert property of the Picture Class"
>
> Cannot figure it out...
>
> Also, does anyone know how to delete the photo from the work sheet when
> you choose a different name?
>
> There are no other pic's on the sheet so maybe a with statement?
>
> Cheers!


--

Dave Peterson
 
Reply With Quote
 
azidrane
Guest
Posts: n/a
 
      15th Mar 2006
Crap. Thanks dave. The thing is we have 194 images, all quite large.
That would really bulk up the size of the file.

Thanks for the info though.

Cheers!

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      15th Mar 2006
Sharing a workbook isn't for wimps <vbg>.

That's one reason why most people don't share workbooks too often <vvbg>.

azidrane wrote:
>
> Crap. Thanks dave. The thing is we have 194 images, all quite large.
> That would really bulk up the size of the file.
>
> Thanks for the info though.
>
> Cheers!


--

Dave Peterson
 
Reply With Quote
 
azidrane
Guest
Posts: n/a
 
      15th Mar 2006
Shared workbooks have become quite useful in our office.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Photo - help Stevep4 Microsoft Excel Misc 1 17th Jan 2009 01:59 AM
Insert Still Photo Music Man Windows XP MovieMaker 1 10th Mar 2008 04:20 AM
Can't insert photo =?Utf-8?B?SnVsaWU=?= Microsoft Frontpage 3 13th Aug 2007 04:16 PM
Why does no photo appear when I insert one =?Utf-8?B?dGVkZWxlcGhhbnQ=?= Microsoft Word Document Management 2 9th Feb 2005 04:07 PM
Insert photo other than bmp Jean MacGregor Microsoft Powerpoint 1 25th Aug 2003 09:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:50 PM.