PDA

View Full Version : Importing pictures by directory string



willspill
12-18-2019, 02:26 AM
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

paulked
12-18-2019, 04:26 AM
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!