Randomizing Import

Hello, I'm trying to create a macro that imports a random file within a specific folder. Below is the code I'm using for the import itself.

Dim impopt As StructImportOptions
Set impopt = CreateStructImportOptions
With impopt
.Mode = cdrImportFull
.MaintainLayers = True
With .ColorConversionOptions
.SourceColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%"
.TargetColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%"
End With
End With
Dim impflt As ImportFilter
Set impflt = ActiveLayer.ImportEx("C:\Users\jaspo\Desktop\PROJECTS\Face generator\Jpgs\Eyes\1.png", cdrPNG, impopt)
Dim s1 As Shape
Set s1 = ActiveShape
ActiveSelection.Move -0.902173, 0.82013
ActiveSelection.AlignAndDistribute cdrAlignDistributeHAlignCenter, cdrAlignDistributeVAlignCenter, cdrAlignShapesToCenterOfPage, cdrDistributeToSelection, False, cdrTextAlignBoundingBox

The one highlighted number is the name of my file. all of the files in the folder are named as numbers 1-14.

is it possible to use the randomize function with this to change the name of the file that it imports?

the randomize function code I'm using is:

Private Function getRandomNumber(nLow As Long, nHigh&) As Long
Dim n1&
n1 = (nHigh - nLow + 1) * VBA.Rnd + nLow
getRandomNumber = n1

End Function

End Sub

another option I thought of was to make a separate module for each file. Then assign a button to randomly activate one of the 14 modules.

But I'm not sure how to do that.

I have also made a userform that has a button that imports the files I want when clicked. I just don't know of a way to make the random button work.

I want it to randomly pick one button from each category.

Hopefully I'm making sense.

I don't really know how to write code, I got most of this through tutorials and recording.

If anyone knows of a way that this could work, I'd really appreciate it.


Parents Reply Children
No Data