I have several functions and subs (appoximately 7) that use the following two lines.
Dim oFolder As Folder
Set oFolder = Application.Session.Folders("Rings").Folders("Contacts").Folders("Customers")
I'd like to create a Private Constant for the module to take the place of those two lines. I've tried Private Const oFolder as Folder = Application.Session.Folders("Rings").Folders("Contacts").Folders("Customers")
, but that gives me a compile error: Expected: type name.
Is this even possible?
I have several functions and subs (appoximately 7) that use the following two lines.
Dim oFolder As Folder
Set oFolder = Application.Session.Folders("Rings").Folders("Contacts").Folders("Customers")
I'd like to create a Private Constant for the module to take the place of those two lines. I've tried Private Const oFolder as Folder = Application.Session.Folders("Rings").Folders("Contacts").Folders("Customers")
, but that gives me a compile error: Expected: type name.
Is this even possible?
Share Improve this question asked Nov 19, 2024 at 22:40 Nathan GuillNathan Guill 758 bronze badges 2 |3 Answers
Reset to default 2Creating the below function worked great. Didn't think about this route when I posted the question.
Private Function CustomerFolder() As Folder
Set CustomerFolder = Application.Session.Folders("Rings").Folders("Contacts").Folders("Customers")
End Function
Per the Documentation, Constants can be declared as: Byte
, Boolean
Integer
, Long
, Currency
, Single
, Double
, Decimal
¹, Date
, String
, or Variant`
Note, first, that Folder
is not in that list — so, no, it is not possible.
Note, second, that those are all Data Types that you assign values to, and not ones that you Set
to an Object Reference. So, no, it's doubly not possible — because Folder
is an object type, not a value type.
¹ Decimal
Constants are not supported in all versions of Visual Basic, so I would advise sticking with Single
or Double
instead
No, it is not possible - you have a sequence of methods calls, not a constant variable. Unless you create a function that takes a string, parses it, and then opens the folders recursively. You can then hardcode the function argument - a string like "\\Rings\Contacts\Customers"
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742394205a4435614.html
oFolder
and have it return the value you want. – braX Commented Nov 19, 2024 at 22:45