Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default Insert a picture in worksheet

I have a below code which,whenever I select a cell(which has a id
number of a person) and run the macro by"ctl+p" it promps userform
with a picture of the person.Now I want,whenever I enter a number and
press a enter button, insert a picture on the top left corner of the
same sheet without calling the user form.Those picture shout be change
everytime I enter the id,or it might be even scan from bar code.Is
that possible? Just for the referance my code is below.
Thanks for the help:


Private Sub UserForm_Initialize()
Dim TM As Double
Dim Prfx As String
Dim Prfxx As String



TM = ActiveCell.Value
Prfx = 6 - Len(Trim(TM))



Select Case Prfx

Case 5
Prfxx = "00000"
Case 4
Prfxx = "0000"
Case 3
Prfxx = "000"
Case 2
Prfxx = "00"
Case 1
Prfxx = "0"
Case 0
Prfxx = ""
End Select
On Error Resume Next

Image1.Picture = LoadPicture("J:\Reference\QT\Team Member Images\" &
Prfxx & TM & ".00.jpg")

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Insert a picture in worksheet

I'm not sure how the barcode stuff would work, but if you're picking up the
picture from a cell on the worksheet (say column A of the row with the
activecell), you could use:

Option Explicit
Sub testme()

Dim myCell As Range
Dim PicName As String
Dim TestStr As String
Dim myPath As String
Dim myPic As Picture

myPath = "U:\my pictures\"

PicName = ActiveCell.EntireRow.Cells(1).Value
If PicName = "" Then
Beep
Exit Sub
End If

PicName = myPath & PicName
TestStr = ""
On Error Resume Next
TestStr = Dir(PicName)
On Error GoTo 0

If TestStr = "" Then
MsgBox "No picture by that name in" & myPath
Exit Sub
End If

'a 3 by 3 range???
Set myCell = ActiveCell.Range("A1").Resize(3, 3)
'or (still a 3 by 3 range
Set myCell = ActiveWindow.VisibleRange.Cells(1).Resize(3, 3)

With myCell
Set myPic = .Parent.Pictures.Insert _
(Filename:=PicName)
myPic.Top = .Top
myPic.Left = .Left
myPic.Width = .Width
myPic.Height = .Height
End With

End Sub

I'm not sure if you meant top of the worksheet (A1) or top of the current
visible range.

baha wrote:

I have a below code which,whenever I select a cell(which has a id
number of a person) and run the macro by"ctl+p" it promps userform
with a picture of the person.Now I want,whenever I enter a number and
press a enter button, insert a picture on the top left corner of the
same sheet without calling the user form.Those picture shout be change
everytime I enter the id,or it might be even scan from bar code.Is
that possible? Just for the referance my code is below.
Thanks for the help:

Private Sub UserForm_Initialize()
Dim TM As Double
Dim Prfx As String
Dim Prfxx As String

TM = ActiveCell.Value
Prfx = 6 - Len(Trim(TM))

Select Case Prfx

Case 5
Prfxx = "00000"
Case 4
Prfxx = "0000"
Case 3
Prfxx = "000"
Case 2
Prfxx = "00"
Case 1
Prfxx = "0"
Case 0
Prfxx = ""
End Select
On Error Resume Next

Image1.Picture = LoadPicture("J:\Reference\QT\Team Member Images\" &
Prfxx & TM & ".00.jpg")

End Sub


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I insert picture into cell so vlookup can return picture? ah Excel Worksheet Functions 1 May 1st 07 04:38 AM
insert a picture in to a comment but picture not save on hard disk Pablo Excel Discussion (Misc queries) 0 February 21st 07 03:48 PM
How can I insert a picture from file while worksheet is protected ChrisYH Excel Discussion (Misc queries) 0 July 27th 05 04:25 AM
How to extract a picture from an Excel worksheet into a picture fi SARANJAI Excel Discussion (Misc queries) 10 June 12th 05 05:00 AM
insert picture in header section of excel worksheet bhavini Excel Discussion (Misc queries) 4 February 22nd 05 08:43 PM


All times are GMT +1. The time now is 10:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"