Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Load Pictures in UserForm from Worksheet

Hi,

I have 5 pictures in worksheet1. I want to see one by one in the
UserForm by clicking Next and Previous Button. how to make this
procedure. pls help me out.

Thanks and regards.

Shahzad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Load Pictures in UserForm from Worksheet

I put 5 pictures in Sheet1.

They were named "Picture 1", "Picture 2", ..., "Picture 5" (note the space
character).

Then I created a small userform with 2 commandbuttons (commandbutton1 and
commandbutton2) and a single image control (Image1).

This code goes in a General module:

Option Explicit
Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(8) As Byte
End Type

Type PICTDESC
cbSize As Long
picType As Long
hImage As Long
End Type

Declare Function OpenClipboard& Lib "user32" (ByVal hwnd As Long)
Declare Function GetClipboardData& Lib "user32" (ByVal wFormat%)
Declare Function CloseClipboard& Lib "user32" ()
Declare Function CopyImage& Lib "user32" (ByVal handle& _
, ByVal un1&, ByVal n1&, ByVal n2&, ByVal un2&)
Declare Function IIDFromString Lib "ole32" (ByVal lpsz As String _
, ByRef lpiid As GUID) As Long
Declare Function OleCreatePictureIndirect Lib "olepro32" _
(pPictDesc As PICTDESC, ByRef riid As GUID, ByVal fOwn As Long _
, ByRef ppvObj As IPicture) As Long

' picTypeConstants:
' None = 0 / Bitmap = 1 / Metafile = 2 / Icon = 3 / EMetafile = 4



This code goes behind the userform:

Option Explicit
Dim WhichImage As Long
Private Sub CommandButton1_Click()
'Prev button
WhichImage = WhichImage - 1
If WhichImage = 0 Then
WhichImage = 5
End If
Call DoTheWork(WhichPicNumber:=WhichImage)
End Sub
Private Sub CommandButton2_Click()
'Next button
WhichImage = WhichImage + 1
If WhichImage = 6 Then
WhichImage = 1
End If
Call DoTheWork(WhichPicNumber:=WhichImage)
End Sub
Private Sub UserForm_Initialize()
With Me.CommandButton1
.Caption = "Prev"
End With

With Me.CommandButton2
.Caption = "Next"
End With
End Sub
Sub DoTheWork(WhichPicNumber As Long)
ThisWorkbook.Worksheets("Sheet1") _
.Shapes("Picture " & WhichPicNumber).CopyPicture xlScreen, xlBitmap
Dim hCopy&
OpenClipboard 0&
hCopy = CopyImage(GetClipboardData(2), 0, 0, 0, &H4)
CloseClipboard
If hCopy = 0 Then Exit Sub
Const IPictureIID = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"
Dim iPic As IPicture, tIID As GUID, tPICTDEST As PICTDESC, Ret&
Ret = IIDFromString(StrConv(IPictureIID, vbUnicode), tIID)
If Ret Then Exit Sub
With tPICTDEST
.cbSize = Len(tPICTDEST)
.picType = 1
.hImage = hCopy
End With
Ret = OleCreatePictureIndirect(tPICTDEST, tIID, 1, iPic)
If Ret Then Exit Sub
Me.Image1.Picture = iPic
'UserForm1.Image1.Picture = IPic
Set iPic = Nothing
' UserForm1.Show
End Sub

=================
The code that does all the real work is from Michel Pierron's post:
http://groups.google.co.uk/group/mic...2a46f0258b86b8

or

http://snipurl.com/30v2c [groups_google_co_uk]



Shazi wrote:

Hi,

I have 5 pictures in worksheet1. I want to see one by one in the
UserForm by clicking Next and Previous Button. how to make this
procedure. pls help me out.

Thanks and regards.

Shahzad


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Load Pictures in UserForm from Worksheet

Change the code in the two button click events to:

Private Sub CommandButton1_Click()
'Prev button
WhichImage = WhichImage - 1
If WhichImage < 1 Then
WhichImage = 5
End If
Call DoTheWork(WhichPicNumber:=WhichImage)
End Sub
Private Sub CommandButton2_Click()
'Next button
WhichImage = WhichImage + 1
If WhichImage 5 Then
WhichImage = 1
End If
Call DoTheWork(WhichPicNumber:=WhichImage)
End Sub



Shazi wrote:

Hi,

I have 5 pictures in worksheet1. I want to see one by one in the
UserForm by clicking Next and Previous Button. how to make this
procedure. pls help me out.

Thanks and regards.

Shahzad


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Load Pictures in UserForm from Worksheet

On Jul 18, 12:16*pm, Dave Peterson wrote:
Change the code in the two button click events to:

Private Sub CommandButton1_Click()
* * 'Prev button
* * WhichImage = WhichImage - 1
* * If WhichImage < 1 Then
* * * * WhichImage = 5
* * End If
* * Call DoTheWork(WhichPicNumber:=WhichImage)
End Sub
Private Sub CommandButton2_Click()
* * 'Next button
* * WhichImage = WhichImage + 1
* * If WhichImage 5 Then
* * * * WhichImage = 1
* * End If
* * Call DoTheWork(WhichPicNumber:=WhichImage)
End Sub

Shazi wrote:

Hi,


I have 5 pictures in worksheet1. *I want to see one by one in the
UserForm by clicking Next and Previous Button. how to make this
procedure. pls help me out.


Thanks and regards.


Shahzad


--

Dave Peterson


Dear Mr. Dave,

Good Evening,

As per your instructions I did every thing, and now I am able to see 5
photos in UserForm, this is what I want exactly.
Thank you very much for your continious support and help.

God Bless you.

Thanks and best regards.

Syed Shahzad
Madinah
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 to load pictures to image boxes in excel with a command button harris (greece) Excel Programming 3 May 21st 07 11:38 AM
Userform does not load Ozgur Pars[_2_] Excel Programming 1 April 13th 07 10:35 PM
Can you load part of a worksheet into a userform wAyne Excel Programming 1 April 9th 06 10:41 PM
Can you load part of a worksheet into a userform Tom Ogilvy Excel Programming 0 April 7th 06 06:30 PM
Load a Userform Nick Excel Programming 1 September 10th 03 03:24 PM


All times are GMT +1. The time now is 12:13 AM.

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

About Us

"It's about Microsoft Excel"