いつもお世話になっております。
Word文書(2010)を開き、指定された文字列を検索し、
その行、頁位置を取得したいのですが、Word VBAでは
以下のコードで可能でしたが、VB.NET2008ではどのようにしたら
良いのでしょうか?
Sub 文字列検索位置取得()
Dim myRange As Range
Dim mySearch As String
Dim a As Long, b As Long
mySearch = InputBox("探す文字を入力してください", "検索")
If mySearch = "" Then Exit Sub
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
'以下を省略すると誤動作が出る可能性があります。
'必要ならオプションを入れてください。
.Text = mySearch
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
Set myRange = Selection.Range
With myRange
'行
a = .Information(wdFirstCharacterLineNumber)
'桁
b = .Information(wdFirstCharacterColumnNumber)
'頁
c = .Information(wdActiveEndPageNumber)
End With
MsgBox c & " 頁 " & a & " 行 " & b & " 桁"
End Sub