0

vba-excel の検索機能に関して私が見つけたすべてのヒントは、同じブックを参照しています。ただし、このコード スニペットのように、別のワークブックをアクティブ化した後

aDifferentWorkbook.Activate
Set Found = Cells.Find(What:=LookedFor.Text, LookIn:=xlValues, LookAt:=xlWhole)

このワークブックには LookedFor.Text が存在しますが、結果は常に Found Is Nothing = True です。別のワークブックに切り替えた後に特別なルールがあるかどうか知っている人はいますか?

ありがとうございます

4

1 に答える 1

2

そのワークブック内のワークシートを実際に選択する必要があります。

aDifferentWorkbook.Activate 'optional
aDifferentWorkbook.Sheets(1).Select
Set Found = Cells.Find(What:=LookedFor.Text, LookIn:=xlValues, LookAt:=xlWhole)

次に、次のシートを選択します。

少しかわいいコードは

  Dim ws As Excel.Worksheet
    For Each ws In aDifferentWorkbook.Worksheets
        Set Found = ws.Cells.Find(What:=LookedFor.Text, LookIn:=xlValues, LookAt:=xlWhole)
    Next ws

選択を回避するため

于 2013-05-15T12:56:21.470 に答える