assistant has telescope even after executed search

I

Ian Elliott

Thanks in advance.
I have a workbook that starts word, opens a file, searches
for a text string, gets a number, close word, and goes
back to excel.

The problem I have is that even after searching for the
text string, the assistant (in my case the paperclip)
still has the telescope in hand. I copied the search part
from a macro recording I did. This is a macro, and the
user doesn't have much time to notice or worry about it,
but I figure I am missing some code. If you could look at
my code and tell me if I did miss something, I would
appreciate it!

Dim wordapp As New Word.Application
With wordapp
.Visible = True 'make visible
.Documents.Open Filename:=pathname(8) & file(8),
ReadOnly:=True 'open read only
.Selection.Find.ClearFormatting 'not sure what this
' does
With .Selection.Find
.Text = "This is the search string"
End With
.Selection.Find.Execute 'execute search
'after previous line assistant holds telescope
.Selection.EndKey unit:=wdLine 'goto end of line
.Selection.MoveStartUntil cset:=vbTab,
Count:=wdBackward 'highlight backwards till tab

MyVar = .Selection 'get number
.Documents.Close savechanges:=wdDoNotSaveChanges 'close
End With
wordapp.Quit
'after previous line assitant stops holding telescope
Set wordapp = Nothing

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top