皆様、宜しくお願い致します。
###前提・実現したいこと
文字通り、Excelブックを開いて、テキスト検索を
行いたい。
このとき、完全/部分一致、数式/値、半角/全角等の
検索条件を指定したい。
###発生している問題・エラーメッセージ
検索条件の指定方法がわからない。
参考にしたサイトより、FindとFindNextの引数として、何らかの書式で
指定すれば好いと思うのですが・・・・。
エラー1:
"FindNext" のオーバーロードで、引数の数が "9" であるものが見つかりません
エラー2:
Range クラスの FindNext プロパティを取得できません。 発生場所 E:\GitRoot\PS1\test_val.ps1:65 文字:13 + ${FindResult} = $SheetName.Cells.FindNext(${FindResult}) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException HRESULT からの例外:0x800A01A8 発生場所 E:\GitRoot\PS1\test_val.ps1:69 文字:18 + if ( ${FindFirst}.Address() -eq ${FindResult}.Address() ) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
ポイントとなる処理:
powershell
1 ${first} = ${result} = ${ws}.Cells.Find(${word}) 2 while (${result} -ne $null) { 3 echo "${childPath}[${wsName}][$(${result}.Row), $(${result}.Column)] : $(${result}.Text)" 4 ${result} = ${ws}.Cells.FindNext(${result}) 5 if (${result}.Address() -eq ${first}.Address()) { 6 break 7 } 8 }
こんな感じ??:
powershell
1 2## After 3set-variable -name After -value "`$A`$1" -option constant 4 5## LookIn 6set-variable -name xlFormulas -value -4123 -option constant 7set-variable -name xlValues -value -4163 -option constant 8#xlComments 9 10## LookAt 11set-variable -name xlWhole -value 1 -option constant 12set-variable -name xlPart -value 2 -option constant 13 14## SeachOrder 15set-variable -name xlByColumns -value 2 -option constant 16set-variable -name xlByRows -value 1 -option constant 17 18## SearchDirection 19set-variable -name xlNext -value 1 -option constant 20set-variable -name xlPrevious -value 2 -option constant 21 22## MatchCase (True or False) 23set-variable -name MatchCase -value $false -option constant 24 25## MatchByte (True or False) 26set-variable -name MatchByte -value $false -option constant 27 28## SearchFormat (True or False) 29set-variable -name SearchFormat -value $false -option constant 30 31 32$LookIn = $xlValues #値 33$LookAt = $xlPart #部分一致 34$SeachOrder = $xlByColumns #列方向に検索 35$SearchDirection = $xlNext #全方向に検索 36 37Find(${word},$After,$LookIn,$LookAt,$SeachOrder,$SearchDirection,$MatchCase,$MatchByte,$SearchFormat)
###結果(解決)
powershell
1 2 ${FindFirst} = ${FindResult} = ` 3 ${SheetName}.Range(${CellRange}).Find(${xText},${FirstCell},${LookIn},` 4 ${LookAt},${SeachOrder},${SearchDirection},${MatchCase},${MatchByte},` 5 ${SearchFormat})
${SheetName} : シート名。オープンしたブックから取得するか、事前設定。
${CellRange} : セル範囲。お約束。Rangeの代わりにCellsでも好いと思うけど、範囲絞る方が?!
${xText} : 検索語句
${FirstCell} : 検索開始位置となるセル番号。
${FindFirst} : 初回検索結果を格納。取得できない時はNull。AddressやらRowやら全部入り。
${FindResult} :二回目以降の検索結果を格納。取得できない時は・・・以下同文。
###参考にした情報
PowerShellで複数のExcelファイルを一括検索する http://qiita.com/nejiko96/items/b423e2dda90181ef524e 条件に当てはまるセルを検索する(Find/FindNext/FindPreviousメソッド) https://www.moug.net/tech/exvba/0050116.html
###補足情報(言語/FW/ツール等のバージョンなど)
Name Value
PSVersion 5.0.10586.63
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.63
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/02/07 04:56