質問編集履歴

3

結果反映

2016/03/12 07:46

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -180,6 +180,38 @@
180
180
 
181
181
 
182
182
 
183
+ ###結果(解決)
184
+
185
+
186
+
187
+ ```powershell
188
+
189
+
190
+
191
+ ${FindFirst} = ${FindResult} = `
192
+
193
+ ${SheetName}.Range(${CellRange}).Find(${xText},${FirstCell},${LookIn},`
194
+
195
+ ${LookAt},${SeachOrder},${SearchDirection},${MatchCase},${MatchByte},`
196
+
197
+ ${SearchFormat})
198
+
199
+ ```
200
+
201
+ ${SheetName} : シート名。オープンしたブックから取得するか、事前設定。
202
+
203
+ ${CellRange} : セル範囲。お約束。Rangeの代わりにCellsでも好いと思うけど、範囲絞る方が?!
204
+
205
+ ${xText} : 検索語句
206
+
207
+ ${FirstCell} : 検索開始位置となるセル番号。
208
+
209
+ ${FindFirst} : 初回検索結果を格納。取得できない時はNull。AddressやらRowやら全部入り。
210
+
211
+ ${FindResult} :二回目以降の検索結果を格納。取得できない時は・・・以下同文。
212
+
213
+
214
+
183
215
 
184
216
 
185
217
  ###参考にした情報

2

問題点を追記

2016/03/12 07:46

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -26,6 +26,160 @@
26
26
 
27
27
  検索条件の指定方法がわからない。
28
28
 
29
+ 参考にしたサイトより、FindとFindNextの引数として、何らかの書式で
30
+
31
+ 指定すれば好いと思うのですが・・・・。
32
+
33
+
34
+
35
+ エラー1:
36
+
37
+ ```
38
+
39
+ "FindNext" のオーバーロードで、引数の数が "9" であるものが見つかりません
40
+
41
+ ```
42
+
43
+ エラー2:
44
+
45
+ ```
46
+
47
+ Range クラスの FindNext プロパティを取得できません。
48
+
49
+ 発生場所 E:\GitRoot\PS1\test_val.ps1:65 文字:13
50
+
51
+ + ${FindResult} = $SheetName.Cells.FindNext(${FindResult})
52
+
53
+ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54
+
55
+ + CategoryInfo : OperationStopped: (:) [], COMException
56
+
57
+ + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
58
+
59
+
60
+
61
+ HRESULT からの例外:0x800A01A8
62
+
63
+ 発生場所 E:\GitRoot\PS1\test_val.ps1:69 文字:18
64
+
65
+ + if ( ${FindFirst}.Address() -eq ${FindResult}.Address() )
66
+
67
+ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68
+
69
+ + CategoryInfo : OperationStopped: (:) [], COMException
70
+
71
+ + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
72
+
73
+ ```
74
+
75
+
76
+
77
+ ポイントとなる処理:
78
+
79
+ ```powershell
80
+
81
+ ${first} = ${result} = ${ws}.Cells.Find(${word})
82
+
83
+ while (${result} -ne $null) {
84
+
85
+ echo "${childPath}[${wsName}][$(${result}.Row), $(${result}.Column)] : $(${result}.Text)"
86
+
87
+ ${result} = ${ws}.Cells.FindNext(${result})
88
+
89
+ if (${result}.Address() -eq ${first}.Address()) {
90
+
91
+ break
92
+
93
+ }
94
+
95
+ }
96
+
97
+ ```
98
+
99
+
100
+
101
+ こんな感じ??:
102
+
103
+ ```powershell
104
+
105
+
106
+
107
+ ## After
108
+
109
+ set-variable -name After -value "`$A`$1" -option constant
110
+
111
+
112
+
113
+ ## LookIn
114
+
115
+ set-variable -name xlFormulas -value -4123 -option constant
116
+
117
+ set-variable -name xlValues -value -4163 -option constant
118
+
119
+ #xlComments
120
+
121
+
122
+
123
+ ## LookAt
124
+
125
+ set-variable -name xlWhole -value 1 -option constant
126
+
127
+ set-variable -name xlPart -value 2 -option constant
128
+
129
+
130
+
131
+ ## SeachOrder
132
+
133
+ set-variable -name xlByColumns -value 2 -option constant
134
+
135
+ set-variable -name xlByRows -value 1 -option constant
136
+
137
+
138
+
139
+ ## SearchDirection
140
+
141
+ set-variable -name xlNext -value 1 -option constant
142
+
143
+ set-variable -name xlPrevious -value 2 -option constant
144
+
145
+
146
+
147
+ ## MatchCase (True or False)
148
+
149
+ set-variable -name MatchCase -value $false -option constant
150
+
151
+
152
+
153
+ ## MatchByte (True or False)
154
+
155
+ set-variable -name MatchByte -value $false -option constant
156
+
157
+
158
+
159
+ ## SearchFormat (True or False)
160
+
161
+ set-variable -name SearchFormat -value $false -option constant
162
+
163
+
164
+
165
+
166
+
167
+ $LookIn = $xlValues #値
168
+
169
+ $LookAt = $xlPart #部分一致
170
+
171
+ $SeachOrder = $xlByColumns #列方向に検索
172
+
173
+ $SearchDirection = $xlNext #全方向に検索
174
+
175
+
176
+
177
+ Find(${word},$After,$LookIn,$LookAt,$SeachOrder,$SearchDirection,$MatchCase,$MatchByte,$SearchFormat)
178
+
179
+ ```
180
+
181
+
182
+
29
183
 
30
184
 
31
185
  ###参考にした情報

1

誤記修正

2016/02/07 04:53

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- PowerShel: Excelブック検索時の条件を指定したい
1
+ PowerShel: Excelブック検索時の条件を指定したい
test CHANGED
File without changes