View Full Version : Linking to a picture
FISHBONE
03-23-2006, 08:41 PM
Hi all:
I am new here and to VBA and am not very good at this.
What I would like to is for example have a list from 1 to 100.
Randomly choose a number between 1 to 100.
After the number is chosen select the picture file coorsponding to the number for example 1.jpg
then display the picture chosen.
I apologize if I am not explaining what I want to do well.
But I greatly appreciate all whom help me and will be adding money to the paypal fund for support.
Thanks again!:beerchug:
Jacob Hilderbrand
03-23-2006, 09:01 PM
You can generate the file name like this.
Dim a As Long
Dim b As Long
Dim r As Long
Dim Path As String
Dim FName As String
'Path To The Files
Path = "C:\MyPics"
'Lowest Number
a = 1
'Highest Number
b = 100
'Generate The Random Number
Randomize
r = Int((b - a + 1) * Rnd + a)
'Store The File Name
FName = Path & "\" & r & ".jpg"
MsgBox FName
Now, how do you want to display the image?
FISHBONE
03-23-2006, 09:24 PM
DRJ, Thank you very much for your help
I would like to just pop open a 5 in. * 5 in picture window in center of the screen.
Thank you very much for your help.
mdmackillop
03-24-2006, 01:06 AM
Hi Fishbone,
Welcome to VBAX.
Something like the following, added to DRJ's code.
Change Top, Left and PicSize to suit
Regards
MD
Dim PicSize As Long
PicSize = 400
ActiveSheet.Pictures.Insert(FName).Select
Selection.Left = 100
Selection.Top = 100
MyScale = PicSize / Selection.Width
Selection.ShapeRange.ScaleWidth MyScale, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight MyScale, msoFalse, msoScaleFromTopLeft
FISHBONE
03-24-2006, 04:43 AM
MD and DRJ your both great.
I don't know if it helps you directly but it does help the site and I have already submitted a donation through paypal to support this website because it is good.
Thanks again!
FISHBONE
mdmackillop
03-24-2006, 09:39 AM
Hi Fishbone
They doubled my pay last year and I still get the same amount! :think:
Regards
MD
Jacob Hilderbrand
03-24-2006, 11:25 AM
Glad to help, and thanks for the donation. :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.