Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA如果工作表不是工作表1或工作表2,并且For Next循环中的布尔值为true_Vba_Excel_If Statement - Fatal编程技术网

Excel VBA如果工作表不是工作表1或工作表2,并且For Next循环中的布尔值为true

Excel VBA如果工作表不是工作表1或工作表2,并且For Next循环中的布尔值为true,vba,excel,if-statement,Vba,Excel,If Statement,整个宏从数据库中提取数据并更新excel中的工作表我基本上是想告诉它更新所有内容,除了两个特定的工作表,一个在末尾,一个在开头。代码已经使用了一段时间,但我想在开头添加一张工作表,但无法使其正常工作 这是有问题的代码 For Each wsSheet In wbBook.Worksheets strName = wsSheet.Name If Not (wsSheet Is (Sheet1)) And _ (blnTF Or (strName = wsActShee

整个宏从数据库中提取数据并更新excel中的工作表我基本上是想告诉它更新所有内容,除了两个特定的工作表,一个在末尾,一个在开头。代码已经使用了一段时间,但我想在开头添加一张工作表,但无法使其正常工作

这是有问题的代码

For Each wsSheet In wbBook.Worksheets
    strName = wsSheet.Name
    If Not (wsSheet Is (Sheet1)) And _
       (blnTF Or (strName = wsActSheet.Name)) _
       Then ... other code
上面的代码工作得很好,但我正在尝试添加Or语句来检查是否不是表1或表2

我是VBA新手,不熟悉语法,从逻辑上我知道我想做什么,并且已经尝试过多次

这也是我试过的

For Each wsSheet In p_wbBook.Worksheets
    strName = wsSheet.Name
    If Not (wsSheet Is (Sheet1) Or (Sheet2)) And _
       (blnTF Or (strName = wsActSheet.Name)) _
       Then .... other code
但它不喜欢或声明,我也尝试了这以外的,如果不是通过写作

If wsSheet is Sheet2 Then
Goto Next 
但它也不喜欢这样


对于Excel为什么不喜欢这种语法的任何帮助,我们将不胜感激

@PAH是正确的。在此上下文中,在OR之后必须有一个完整的语句

(condition 1) Or (condition 2)

改为:

If Not (wsSheet Is (Sheet1) Or wsSheet Is (Sheet2)) And _

出于测试目的,我使用了以下方法:

For Each wsSheet In wbBook.Worksheets
    strName = wsSheet.Name
    If Not (strName = "Sheet1" Or strName = "Sheet2") And (blnTF Or (strName = wsActSheet.Name)) Then
        MsgBox (strName)
    End If
Next wsSheet

你不能那样写你的陈述。它必须是“如果不是(wsSheet是(Sheet1)或wsSheet是(Sheet2))等。