Interacting with Multiple Word Objects/Documents VB6/VBA

J

jCheah

Hi everyone,

FYI, I am working on a VB6/VBA program that can reformat word
documents like replace certain words with certain characters. Here's
the little detail about part of my program. When the program read the
selected document, it uses find/replace to replace certain words. In
order to use this, I have to select a portion of the document and then
use the following codes

objWord.Selection.Find

The problem with that is i want to allow the user to work on some
other word documents or outlook emails when my program is running.
When the user selects another document, I get an error, because it is
trying to perform the actions on their selection on new word document
instead of the selection found by my app.

And also i believe the code "objWord.Application.ActiveWindow" is
causing problem too as when the user open another new word document to
work with when the program is running, the new word document will
become the "ActiveWindow".

So is there anyway to let the user to work on some other Word-related
works when my program is running? Because when i run my program, the
process will take about 20 mins to finish, it's illogical to have the
user waited for 20mins without working on other Word-related works. I
want the user to be able to multitasking.


The following is small part of my code

Dim objWord As New Word.Application
Dim objDoc As New Word.Document
Dim formName as String

'Open the Word Doc based on the file path set on the textbox
Set objDoc = objWord.Documents.Open(filePath)


With objDoc.Application


'----------------------------------------------------------------------------------------------------------------
'*#1 Get the title name from the header of word document

'----------------------------------------------------------------------------------------------------------------

If .ActiveWindow.View.SplitSpecial <> wdPaneNone Then
.ActiveWindow.Panes(2).Close
End If
If .ActiveWindow.ActivePane.View.Type = wdNormalView
Or .ActiveWindow.ActivePane.View.Type = wdOutlineView Then
.ActiveWindow.ActivePane.View.Type = wdPrintView
End If
.ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader
.Selection.MoveRight unit:=wdCell
.Selection.MoveRight unit:=wdCell
.Selection.MoveRight unit:=wdCell

formName = .Selection.Text

.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument



'----------------------------------------------------------------------------------------------------------------
'*#2 Find and Replacement Procedure (Mark Heading)

'----------------------------------------------------------------------------------------------------------------
'.Visible = True

.Selection.HomeKey unit:=wdStory


'set the find criteria based on the following font and
paragraph format
.Selection.Find.ClearFormatting
With .Selection.Find.Font
.Size = 10
.Bold = True
End With

With .Selection.Find.ParagraphFormat
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
.Alignment = wdAlignParagraphLeft
End With

'Selection.Find.Style = ActiveDocument.Styles("outlinehd1")

'set the replacement criteria where all the matches will be
marked wtih Underlines and Strikethrough
.Selection.Find.Replacement.ClearFormatting
With .Selection.Find.Replacement.Font
.Underline = wdUnderlineDouble
.UnderlineColor = wdColorAutomatic
.Strikethrough = True
End With

With .Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
End With

'execute the find and replacement on all matches
.Selection.Find.Execute Replace:=wdReplaceAll

End With


Any help would be deeply appreciated. thanks..
 
D

David Sisson

Perhaps...

objDoc.Activate

Read the help file on Activate. Activate effects Documents, Windows, Panes
and Tasks.
 

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