Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 21

Thread: Image Viewer in VBA?

  1. #1

    Image Viewer in VBA?

    Is it possible to create a simple image viewer in vba? Im thinking of a picture box with some controls and a drive/data list to view the file in the directory and if click the image will load on picture box. Is this possible? Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What would drive which picture is shown? You could load all picture filenames into an array, and use a slider to pick up the next in the array.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3


    It looks like something like this one.
    Can you please show me some demo to start on?
    Thanks

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What looks something like this one? How does that picture answer what I said?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    What would drive which picture is shown?
    Sorry I didnt catch that. I mean I was trying to picture out what I mean on that foto.

  6. #6
    could you show me some example xld sir? Thanks.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Here is an example of what I was suggesting.
    Attached Files Attached Files
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    Yes that xld something like that but with list of images inside the directory/path given. Would that be integrated to form rather than in the worksheet?

    Thanks so much for the help

  9. #9
    xld can you help me again to integrate it in the form instead of inside the worksheet. I was trying but the foto is not showing up.

  10. #10
    Anyone can help me implementing it to form rather than in the worksheet? Thanks

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this
    Attached Files Attached Files
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    Oh my thats perfect xld. I wonder if we could add zoom in and zoom out in the image? This is really what i need
    Thanks so much

  13. #13
    @xld
    I tried your Image viewer it look nice but I encounter some problem, After sometimes the image was loaded it stuck on a single image even you click some items on the list, even if you reload the image dir it will be stuck on a certain photo, the solution was to re run the form. What could be the cause of that? A memory issue? Would be better as well if it can be zoomed, a very potential project.
    Last edited by defcon_3; 05-26-2012 at 01:58 AM.

  14. #14
    And here is another viewer if you want.
    Attached Files Attached Files

  15. #15
    I have modified the your image viewer jolivanes answering OP request as well to make image appear on the list. But there are strange things that happen which I do not know which causes error. If I browse a folder and click item on the list it says Unable to load image but when I open the Image Viewer posted by jolivanes and load an image and return to the Image Viewer I modified and broswe again a folder and click an Item in the list the image will show. So I dont know why I have to load first the image viewer of jolivanes to make my modified image viewer works. Any idea about this issue? I attached the Image Viewer I modified.
    Attached Files Attached Files

  16. #16
    jolivanes and DefCon thanks but it cant load the image no error promt just the message box stating "Unable to load image"

  17. #17
    I think you have to read my above post. Load some image first with the viewer jolivanes created the try to browse the again on my mod and click item on the list and youll see image will load. Strange huh.

  18. #18
    Here is another picture viewer that works in excel 2003.
    Does not work in 2007 (Application.Filesearch)

    If someone makes it work in 2007, I would not mind getting a copy.

    Thanks
    Attached Files Attached Files

  19. #19
    Thanks for all the help I got it sorted out

  20. #20
    @jolivanes, I dont know if your aware of this error. i combined your code with the code I added. Using the left pane by browsing per folder, will cause returns to null and causes error, when the item is loaded try browsing per file with the below browser and try to click again to the items and it will now load the images. After sometime it will again result error and you need to reload any single file again to make the item load again. I wonder what causes this error. I appreciate your help but unfortunately Im trying to make it work on 2007 version.

    I guess the error reside on this area

    [VBA]
    Sub LoadImage(Name As String)

    If Dir(Name) <> "" Then
    With Image1
    .AutoSize = True
    .Picture = LoadPicture(Name)
    m_sngHeight = .Height
    m_sngWidth = .Width
    .AutoSize = False
    .PictureSizeMode = fmPictureSizeModeStretch
    m_sngZoom = 1
    .Left = 1
    .Top = 1
    End With
    SetZoom m_sngZoom
    Else
    MsgBox "Unable to load image " & Chr(10) & Name, vbExclamation
    End If
    End Sub
    [/VBA]

    [VBA]
    Private Sub cmdDir_Click()
    Dim MyFolder As String
    Dim MyFile As String

    With Application.FileDialog(msoFileDialogFolderPicker)

    If .Show = -1 Then

    lstImages.Clear

    txtDir.Text = .SelectedItems(1)
    MyFile = Dir(.SelectedItems(1) & "\*.jpg")
    Do While MyFile <> ""

    lstImages.AddItem MyFile
    MyFile = Dir
    Loop
    End If
    End With
    End Sub
    [/VBA]

    I guess it has something to do with the dir why image returns null on Load Image. Any ideas?
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •