繁体   English   中英

如何在VBA 2003中使用InStr函数?

[英]How to use InStr function in VBA 2003?

下面的代码在InStr调用中返回错误5:

Option Explicit

Sub Test()
     Dim wb As Workbook
     Dim wbs As Workbooks
     Dim str As String
     Dim LPosition As Integer

     Set wbs = Application.Workbooks
     For Each wb In wbs
        str = wb.Name
        LPosition = InStr(0, str, "_", vbTextCompare)
        MsgBox LPosition
     Next wb
End Sub  

有人可以解释为什么吗?

InStr函数的起始索引从1开始=> 0是无效值。

请参阅http://msdn.microsoft.com/zh-cn/library/8460tsh1%28v=vs.80%29.aspx的“ 例外”部分

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM