I am aware I'm not the first to have this question. Still I cannot find the solution. I have some vba code for my solidworks, that works fine. However, I want to use a string that I defined in one sub, in another sub. This seems harder than I thought.
My code - simplified:
Public FolderName As String
Public Sub SaveFiles()
FolderName = "SOLID"
End Sub
Public Sub UserInput(Parameter1, Parameter2, Parameter3...as string) 'A lot of input from a userform
For i = LBound(ArrayList) To UBound(ArrayList)
Debug.Print "FolderName = ", FolderName 'THIS PRINTS EMPTY AND I WANT IT TO PRINT "SOLID"
Next
End Sub
I use public subs and a public string. I cannot add FolderName
to Sub UserInput(FolderName)
, because then I get the compile error "Argument not optional" for my Call UserInput()
that is written in my Userform
What can I do to solve this?
Public Sub UserInput(ParameterX As String, Optional FolderName As String = "a better default")
doTheThings
End Sub