PDA

View Full Version : Solved: Does Selection.Find Require Visible:=True?



xCav8r
06-13-2005, 10:07 AM
This only seems to be working when Visible:=True. How can I do this without making it visible?


ChangeFileOpenDirectory strPathToDataDirectory
Documents.Open FileName:=strDataSourceName, Visible:=False
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "|"
.Replacement.Text = Chr(34)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With


Same issue...

Dim objWord As Object
Set objWord = New Word.Application
With objWord
.Visible = False
.ChangeFileOpenDirectory strPathToDataDirectory
.Documents.Open FileName:=strDataSourceName
.Selection.HomeKey unit:=wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "|"
.Replacement.Text = Chr(34)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
.Documents(strDataSourceName).Close wdSaveChanges
End With

MOS MASTER
06-13-2005, 10:18 AM
Hi, :yes

Don't use Selection if you wanna work hidden! Use the Range object instead.

This will work:
Sub Invisible()
Dim oApp As New Word.Application
Dim oDoc As Word.Document
Set oDoc = oApp.Documents.Open(FileName:=strDataSourceName, Visible:=False)
With oDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "|"
.Replacement.Text = Chr(34)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
oApp.Visible = True 'Test
Set oDoc = Nothing
Set oApp = Nothing

End Sub


Later..:whistle:

xCav8r
06-13-2005, 10:20 AM
Argh, I have to learn a new object!!!!!!!!!!!!!!!!!!! :P

Alright, thanks.

MOS MASTER
06-13-2005, 10:25 AM
Argh, I have to learn a new object!!!!!!!!!!!!!!!!!!! :P

Alright, thanks.
No not really just forget that lousy Selection Object and always use the Range object if you can! (Sometimes you need Selection)

Range object is always faster. (perhaps not always but 99% of the cases)

You're Welcome! :beerchug:

xCav8r
06-13-2005, 10:31 AM
Beauty. Working.

MOS MASTER
06-13-2005, 10:34 AM
Beauty. Working.
On to the next challenge! :hi: