PDA

View Full Version : Leading zeroes depending on file name



willspill
01-22-2020, 07:10 AM
Hi,

I am currently uisng the following code to import an image into Excel:


ActiveSheet.Shapes.AddPicture _
(filename:=folder_path & "\run-" & Format(j, "000") & "\" & file_name & "-" & Format(i, "000") & "." & input_file_type, _
linktofile:=msoFalse, savewithdocument:=msoCTrue, _
Left:=50, Top:=250, Width:=2500, Height:=2500).Select

The i and j values are used inside a For loop. My question is, is it possible for the code to read the format of the file and apply a suitable amount of leading zeroes to import it? For example, the current format of the file is 'plot-001-001.png' where file_name (plot-001) and input_file_type (png) are defined by the user. The imported files have the capability to be of the format 'plot-001-000001' depending on the amount of files to import.


Any ideas? Thanks.