admin管理员组文章数量:1336728
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"
本文标签: vbaPrivate Const oFolder as FolderStack Overflow
版权声明:本文标题:vba - Private Const oFolder as Folder - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742394205a2466591.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
oFolder
and have it return the value you want. – braX Commented Nov 19, 2024 at 22:45