Results 1 to 18 of 18

Thread: Excel Image Viewer and Rename its File Name

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    443
    Location
    Option Explicit was not in module of file I downloaded. That's why I mentioned it. I added it and found a variable that had not been declared.

    I still don't know what you mean by "full size". Looks big enough to me. If you want to view in an external image app, managing that would be more difficult.

    Need to add code that disables/enables Prev/Next buttons when on first or last file.
    Also make sure Filelist is cleared before reading in file names from selected folder.

    Consider this revised code:
    Option Explicit
    Dim v_row As Integer
    Dim v_filecount As Integer
    
    Sub LoadNextImage()
        If v_row < v_filecount Then
            LoadImage 1
        Else
            MsgBox "This is last image"
        End If
    End Sub
    
    Sub LoadPrevImage()
        If v_row > 3 Then
            LoadImage -1
        Else
            MsgBox "This is first image"
        End If
    End Sub
    
    Sub LoadImage(intDirection)
        Sheets("Update").Range("K9").Value = Sheets("Update").Range("K9").Value + intDirection
        v_row = Sheets("Update").Range("K9").Value
        Sheets("Update").Image1.Picture = LoadPicture(Sheets("Filelist").Range("B1").Value & Sheets("Filelist").Range("B" & v_row).Value)
        Sheets("Update").Range("K7").Value = Sheets("Filelist").Range("B" & v_row).Value
    End Sub
    
    Function GetImageDirectory() As String
        Dim v_imagefolder As FileDialog
        Dim v_imageitem As String
        Set v_imagefolder = Application.FileDialog(msoFileDialogFolderPicker)
        With v_imagefolder
            .Title = "Select the Image Folder"
            .AllowMultiSelect = False
            .InitialFileName = Application.DefaultFilePath
            If .Show <> -1 Then GoTo NextCode
            v_imageitem = .SelectedItems(1)
        End With
    NextCode:
        If Right(v_imageitem, 1) <> "\" Then
            v_imageitem = v_imageitem & "\"
        End If
        GetImageDirectory = v_imageitem
        Set v_imagefolder = Nothing
    End Function
    
    Sub ListImageFiles()
        Dim v_fldrpath As String, v_pth As String, Filename As String
        v_fldrpath = GetImageDirectory
        Sheets("Filelist").Range("B1").Value = v_fldrpath
        v_pth = v_fldrpath
        Filename = Dir(v_pth)
        Sheets("Filelist").Range("A3:B" & Sheets("Filelist").Cells.SpecialCells(xlCellTypeLastCell).Row).Clear
        Do While Filename <> ""
            v_filecount = v_filecount + 1
            Sheets("Filelist").Range("A" & v_filecount + 2).Value = v_filecount
            Sheets("Filelist").Range("B" & v_filecount + 2).Value = Filename
            Filename = Dir()
        Loop
        Sheets("Update").Range("K9").Value = 3
        LoadImage 0
    End Sub
    
    Sub ChangeName()
        Dim oldname As String, newname As String
        oldname = Sheets("Filelist").Range("B1").Value & Sheets("Update").Range("K7").Value
        newname = Sheets("Filelist").Range("B1").Value & Sheets("Update").Range("K11").Value
        Name oldname As newname
        v_row = Sheets("Update").Range("K9").Value
        Sheets("Filelist").Range("B" & v_row).Value = Sheets("Update").Range("K11").Value
        LoadImage 0
    End Sub
    Last edited by June7; 03-22-2024 at 12:35 AM.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Posting Permissions

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