【问题标题】:VBA Excel : Compile Error when using .activate on a sheetVBA Excel:在工作表上使用.activate时编译错误
【发布时间】:2013-12-20 12:30:27
【问题描述】:

我在尝试执行 Excel 宏时遇到以下错误: 编译错误:需要函数或变量。

这是我的代码:

            'On split le libellé afin de récupérer la chaîne de caractère source1 à rechercher dans la colonne B du PSR
            TabSrcDoubleEntree = Split(PtoutPar(j).Nom, "/")
            ' on récupère la ligne du PSR (colonne B) dans laquelle la chaîne source 1 (=TabSrcDoubleEntree(0)) est renseignée
            Set sheet = Workbooks(PFile).Sheets(ParMap(j).Parametrage.SrcFeuille)
            **With sheet.Activate**
                Set celluleRowRange = .Range("B", .Range("B").End(xlUp))
                Set celluleFind = celluleRowRange.Find(TabSrcDoubleEntree(0), LookIn:=xlValues, lookat:=xlWhole)
                celluleRowFind = celluleFind.Row
            End With
            'on initialise la ligne à partir de laquelle on fait la recherche à "c.Row"
            ThisWorkbook.Sheets(PFeuilleDest).Cells(iDest, ParMap(j).Parametrage.DestCol).Value = Workbooks(PFile).Sheets(ParMap(j).Parametrage.SrcFeuille).Cells(celluleFind.Row + ParMap(j).Parametrage.SrcPremiereLigne, ParMap(j).Parametrage.SrcCol).Value

=> 有谁知道为什么说明书.Activate 不正确??

非常感谢 西蒙

【问题讨论】:

标签: vba excel-2007


【解决方案1】:

With "this" 语句用于从"this" 的上下文执行以下块。在您的情况下,您正在从 Activate 函数的上下文执行块,而不是 sheet 本身,这会引​​发编译错误。我建议将其更改为以下内容

' Perform the following from the context of sheet    
With sheet
    .Activate
    Set celluleRowRange = .Range("B", .Range("B").End(xlUp))
    ' ...
End With

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多