从你的问题中不清楚你为什么会得到无效限定符错误。也许是因为你试图在VBA中使用VB.NET语法?但是,如果实际使用VB.NET,下面的代码应该为你工作:
Public Function FormatDateAndName(theDate As Date, theName As String) As String
Return theDate.ToString("ddMMMM") & theName
End Function
然后,你可以这样调用它:
Dim myDate As New Date(2004, 1, 1)
Dim myName As String = "_lole"
Dim dateAndName As String = FormatDateAndName(myDate, myName)
Console.WriteLine(dateAndName) ' Outputs "04Jan_lole"
在VBA(而非VB.NET ),你应该能够使用它像这样:
Public Function FormatDateAndName(theDate As Date, theName As String) As String
FormatDateAndName = Format(theDate, "ddMMMM") & theName
End Function
然后你就可以这样调用:
Dim result As String
result = FormatDateAndName(#1/1/2004#, "_lole")
MsgBox(result)
你在哪里看到*“invalid qualifier error”*?它在设计时还是运行时?哪行代码导致错误?错误的全文是什么?如何声明'StrField'?它是什么类型? – 2014-10-28 14:41:30
哦,等等......这是VBA吗?我假设,基于示例代码和问题的标签,你在VB.NET中编写代码。如果您试图在VBA中运行此代码,那肯定会解释为什么它不起作用。 VBA和VB.NET是完全不同的语言。 – 2014-10-28 14:49:54