Visual Basic and Macro's

  • Thread starter Thread starter Kevin Oswald
  • Start date Start date
K

Kevin Oswald

I have a program which is obtaining a string from a user,
accessing a Word file, firing a macro which finds the
string in the file, then positions the Word file to
display the results (hope that makes sense). The Word
file is a chart and when the string is displayed, the
vertical position of the string is random (or seems to
be). Is there are command which always places the cell
which contains the string at the top of the screen?

Thanks in advance,
Kevin Oswald
 
Not entirely sure I understand exactly what you want, but you could use the
following:

Selection.Find.ClearFormatting
With Selection.Find
.Text = strTxtToFind
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Copy
Selection.HomeKey Unit:=wdStory
Selection.TypeParagraph
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Paste

The text you are searching for is in the string variable strTxtToFind. This
text is found, copied and the HomeKey Unit is used to go to the top of the
word document where the text is pasted after moving the line down one first.

Whether or not you can use this depends on how I have understood your
requirement.

Hope this helps
Martin
 
Back
Top