Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Interacting with Multiple Word Objects/Documents VB6/VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jCheah@iso.com - 17 Jul 2007 21:47 GMT
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..
David Sisson - 18 Jul 2007 19:02 GMT
Perhaps...

objDoc.Activate

Read the help file on Activate.   Activate effects Documents, Windows, Panes
and Tasks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.