bub*_*bub 0 excel vba excel-vba
Private Sub Workbook_Open()
Dim WBname As String
WBname = ThisWorkbook.name
If Not InStr(WBname, "test") > 0 Then
MsgBox ("NotOK")
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
编辑:更多说明.
我现在测试"测试"是否在工作簿名称中.
但我想测试是否有更多的单词而不仅仅是"测试"在工作簿名称中没有复制粘贴代码一千次.
使用此项如果WBname必须包含所有单词
Dim WBname As String
WBname = ThisWorkbook.Name
Dim arrWords As Variant, aWord As Variant
arrWords = Array("aa", "bb", "cc") 'input your words list here
For Each aWord In arrWords
If Not InStr(WBname, aWord) > 0 Then
MsgBox ("NotOK")
Exit For
End If
Next
Run Code Online (Sandbox Code Playgroud)
如果WBname必须包含至少一个单词,请使用此选项
Dim WBname As String
WBname = ThisWorkbook.Name
Dim arrWords As Variant, aWord As Variant
arrWords = Array("aa", "bb", "cc") 'input your words list here
Dim wordFound As Boolean
wordFound = False
For Each aWord In arrWords
If InStr(WBname, aWord) > 0 Then
wordFound = True
Exit For
End If
Next
If Not wordFound Then
MsgBox ("NotOK")
End If
Run Code Online (Sandbox Code Playgroud)