簡體   English   中英

VBA Excel:在工作表上使用.activate時發生編譯錯誤

[英]VBA Excel : Compile Error when using .activate on a sheet

當我嘗試執行它時,我在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

=>有誰知道為什么說明表。激活不正確?

非常感謝西蒙

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM