Consulting

Results 1 to 2 of 2

Thread: Importing pictures by directory string

  1. #1

    Importing pictures by directory string

    Hi,

    I am currently trying to improve the code below in which an image is defined by the user by a directory string using the file dialog. This code takes the file directory named 'C:\...\plot-001-001.jpg' (The file currently must have this format for the loop to work) and minuses the last 5 digits so that a loop can add the number 1-9. The images numbered 1-9 will be have their background removed and be layered and saved to a single image using further code. The problem with this method is it will only work if the folder containing the images contains 9 or less. Eventually I would like the user to be able to define the number of images within the folder that they wish to use which also defines the loop range.

    I understand this is a very broad question but is there a better way to do this? I hope I have described the objective well enough.

    Thanks

    FYI, partialpath is defined for the module as a string which is why it doesn't appear here.

    Sub FileOpenDialogBox()

    Dim fullpath As String
    With Application.FileDialog(msoFileDialogFilePicker)
    .AllowMultiSelect = False
    .Show

    fullpath = .SelectedItems.Item(1)
    partialpath = Left(fullpath, Len(fullpath) - 5)
    End With

    End Sub

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    I wouldn't say this was better:

    Sub FileOpenDialogBox()
        With Application.FileDialog(msoFileDialogFilePicker)
            .AllowMultiSelect = False
            .Show
            partialpath = Left(.SelectedItems.Item(1), Len(.SelectedItems.Item(1)) - 5)
        End With
    End Sub
    But it is shorter!
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

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