A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Multiple Instances of Word?



 
 
Thread Tools Display Modes
  #1  
Old September 21st, 2004, 01:41 AM
Bruce Hutfless
external usenet poster
 
Posts: n/a
Default Multiple Instances of Word?

I need multiple instances of Word running, so that I don't muck with other
intances that maybe ruuning

Assume, Office 2003 (Word in particuliar)

VB6 code here -----

Dim oApp As Word.Application
Dim oDoc As Word.Document


Private Sub Command1_Click()
Command1.Enabled = False
' Start Word.
Set oApp = CreateObject("Word.Application")
'create document from template
Set oDoc = oApp.Documents.Add(Template:="C:\Source
Code\Dev\WordTstVB6\MyNormal.dot")
'This function demostrates above command not as expected
Dim oTmpl As Word.Template
For Each oTmpl In oApp.Templates
If oTmpl.Name = "Normal.dot" Then
'what goes here to remove Normal.dot from collection?
End If
Next
'Save our newly created document which should only have our template
oDoc.SaveAs ("C:\Source Code\Dev\WordTstVb6\MyDocument.doc")
'Open document
Set oDoc = oApp.Documents.Open("C:\Source
Code\Dev\WordTstVB6\MyDocument.doc")
'Set customazition context
oDoc.Application.CustomizationContext =
oDoc.Application.ActiveDocument()
'Supposedly, in our context only standard toolbar (commandBar) is
removed
For Each Item In oApp.CommandBars
If Item.Name = "Standard" Then
Item.Enabled = False
End If
Next
oApp.Visible = True
Command1.Enabled = False
Command2.Enabled = True
Command2.SetFocus

End Sub

Private Sub Command2_Click()
'Restore commadBars
For Each Item In oApp.CommandBars
Item.Enabled = True
Next

'Next line of code does function as expected.
For Each Item In oApp.Documents
If Item.Name = oDoc.Name Then
Item.Close Word.WdSaveOptions.wdSaveChanges
End If
Next

oApp.Quit Word.WdSaveOptions.wdDoNotSaveChanges
Set oApp = Nothing
Command1.Enabled = True
Command2.Enabled = False
Command1.SetFocus

End Sub


VB .Net code here ----

Private WithEvents ThisApplication As MSWord.Application

Private WithEvents ThisDocument As MSWord.Document

'This function launches MS Word and Opens A Dcoument

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Button1.Enabled = False

Try

' Start Word.

ThisApplication = New MSWord.Application

'create document from template

ThisDocument = ThisApplication.Documents.Add(Template:="C:\Source
Code\Dev\WFBruce\MyNormal.dot")

'This function demostrates above command not as expected

For Each oTmpl As MSWord.Template In ThisApplication.Templates

If oTmpl.Name = "Normal.dot" Then

End If

Next

'Save our newly created document which should only have our template

ThisDocument.SaveAs("C:\Source Code\Dev\WFBruce\MyDocument.doc")

'Open document

ThisDocument = ThisApplication.Documents.Open("C:\Source
Code\Dev\WFBruce\MyDocument.doc")

'Set customazition context

ThisDocument.Application.CustomizationContext =
ThisDocument.Application.ActiveDocument()

'Supposedly, in our context only standard toolbar (commandBar) is removed

For Each oCommandBar As Office.CommandBar In ThisApplication.CommandBars

If oCommandBar.Name = "Standard" Then

oCommandBar.Enabled = False

End If

Next

ThisApplication.Visible = True

Button1.Enabled = False

Button3.Enabled = True

Catch ex As Exception

Button1.Enabled = True

MsgBox(ex.ToString, MsgBoxStyle.Critical)

ThisApplication.Quit(MSWord.WdSaveOptions.wdDoNotS aveChanges)

End Try

End Sub



' this function closes our open document, restores CommandBars and Quits MS
Word

Private Sub Button3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button3.Click

If Button1.Enabled Then

Button3.Enabled = False

Exit Sub

End If

If Not ThisApplication Is Nothing Then

For Each oCommandBar As Office.CommandBar In ThisApplication.CommandBars

oCommandBar.Enabled = True

Next

'Next line of code does function as expected.

For Each oDoc As MSWord.Document In ThisApplication.Documents

If oDoc.Name = ThisDocument.Name Then

oDoc.Close(MSWord.WdSaveOptions.wdSaveChanges)

' this could does not work correct becuase this instance of Word

' should only contain single document

'instead every open document for every instace in collection

'next, line of code can not be executed other all documents in every
instance of Word closed

'Else

' oDoc.Close(MSWord.WdSaveOptions.wdDoNotSaveChanges )

End If

Next

'This line of code does not function correctly

'if another instances is openned after button1 clicked, then both instances
close.

'also, must include close option other Normal.dot change dialog pops up.

'ThisApplication.Quit()

ThisApplication.Quit(MSWord.WdSaveOptions.wdDoNotS aveChanges)

ThisApplication = Nothing

End If

Button1.Enabled = True

Button3.Enabled = False

End Sub



Steps to repeat problem ----

First test expected behavior ----

1) Launch Word by start-All Programs-Microsoft Office-Microsoft Office
Word 2003,

result: a) MDI windows opens with Document 1 window

2) Launch WFBruce.sln and build project and run project

result: a) Visual Studio .Net launches, project builds, Windows Form
Displayed,

b) previous Word MDI window on screen

3) Click Open Document button on WFBruce windows form

result: a) second instance of Word MDI window with MyDocument displayed only
Standard CommandBar (ToolBar missing)

b) previous Word MDI window on screen full commandBars

4) Click Close Document button on WFBruce windows form

result: a) second instance of Word closes correctly

b) previous Word MDI window on screen

5) Close Word launched in step 1.

So far so good ---

Second test, unexpected behavior ----

1) launch WFBruce.sln and build project and run program

2) Click Open Document button on WFBruce windows form

result: instance of Word MDI window with MyDocument displayed only Standard
CommandBar (ToolBar missing)

3) Launch Word by start-All Programs-Microsoft Office-Microsoft Office
Word 2003,

result: a) MDI windows opens with Document 1 window, however "We have a
problem Huston!", (Toolbar missing)

4) Click Close Document button on WFBruce windows form

result: a) all Word windows close!, "Huston, we have a serious prolbem1",
Both instances of Word closed. Very unexpected behavior.



Anyone know how to get around this?

Anyone else need to have something like this work? How did you accomplish
it?



Regards,



Bruce Hutfless


  #2  
Old September 21st, 2004, 10:55 AM
Cindy M -WordMVP-
external usenet poster
 
Posts: n/a
Default

Hi Bruce,

It's a bit difficult to follow what you consider to be the actual
problem(s), but...

By installation default, if you start Word through the UI, it automatically
picks up and uses any existing instance of Word. It will not, by default,
start a new instance. There are various reasons for this, among them:

- conflicts with customizations (Normal.dot is locked)
- uses more system resources
- confusing to the user ("I did x in window a, but I don't see it in
window b")

3) Launch Word by start-All Programs-Microsoft Office-Microsoft Office
Word 2003,

result: a) MDI windows opens with Document 1 window, however "We have a
problem Huston!", (Toolbar missing)

4) Click Close Document button on WFBruce windows form

result: a) all Word windows close!, "Huston, we have a serious prolbem1",
Both instances of Word closed. Very unexpected behavior.


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

  #3  
Old September 21st, 2004, 06:24 PM
Bruce Hutfless
external usenet poster
 
Posts: n/a
Default

Cindy,

Thanks for responding. I understand your confusion now that I re-read my
post along side yours. I think we are in complete agreement, my use of Word
is very different from anything you would do with Word. I am treating Word
as programming control, not an end user application, thus as control, I
don't want to muck with the user experience or environment, and as a
programmer I should the option to specify the behavior I need from Word, and
while you make good points about the user, I don't believe I made my self
clear.

I think Word and most Office Applications are broken, specifically becuase
of the test I outline, but for very different reasons.
I want to perserve any changes the user makes and I understand that
agruement, however, Word offers me functionality that would be expensive to
recreate, and thus I desire to use Word as programming control, not as an
end-user tool.

The prolem is that I want to embed Word editting power inside an authoring
application, while perserving Word's (user experience) outside of the my
application. Since MS has dropped the MDI paradigm, and yes I know "users"
where asking for this, it has made my life as application developer
impossible.

I have not been able to get anywhere with anyone at Microsoft and that is
why many Enterprise developer's still insist the Office is still not
enterprise possible.

I posted here at Microsoft's suggestion, so we will see if any developers
have ideas.

For myself, I've just completed re-engineering the winword.exe and have
found several ways around the problem I have Word, it involves some very
ugle and trick hooking of low-level windows and winword calls, but I will
get back the behavior my user's are demanding! I just means I will have to
Word version specific installs and code, but that appears to be the life of
application developer in Windows world.

Life for me and other developers would have been a lot simpler if MS would
have documented the API to winword.exe just like they have done for Internet
Explorer, where I can use IE as a control without mucking up the user
experience.

As it is, when I use Word as control I have to muck up the user experience
and that is just poor practice.

I'm open to any developer solutions.

Regards,

Bruce Hutfless
Chief Engineer
SchoolKiT International
email:
web:
www.schoolkit.com


"Cindy M -WordMVP-" wrote in message
news:VA.00009f20.007f0a27@speedy...
Hi Bruce,

It's a bit difficult to follow what you consider to be the actual
problem(s), but...

By installation default, if you start Word through the UI, it
automatically
picks up and uses any existing instance of Word. It will not, by default,
start a new instance. There are various reasons for this, among them:

- conflicts with customizations (Normal.dot is locked)
- uses more system resources
- confusing to the user ("I did x in window a, but I don't see it in
window b")

3) Launch Word by start-All Programs-Microsoft Office-Microsoft Office
Word 2003,

result: a) MDI windows opens with Document 1 window, however "We have a
problem Huston!", (Toolbar missing)

4) Click Close Document button on WFBruce windows form

result: a) all Word windows close!, "Huston, we have a serious prolbem1",
Both instances of Word closed. Very unexpected behavior.


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



  #4  
Old September 28th, 2004, 01:35 PM
Cindy M -WordMVP-
external usenet poster
 
Posts: n/a
Default

Hi Bruce,

I do some development, so I know the problem you're having. It's just that
you've posted in an end-user newsgroup, so your question was really open for
interpretation :-) If you want a developer's POV, probably one of the
office.developer newsgroups would be more productive.

Besides the workarounds you've mentioned, the other approach that occurs to me
- since you're apparently developing for a specific audience - would be to
change the Registry setting for the Word appliction to always do the equivalent
of the /w starup switch (= always new instance when a document is
double-clicked or an Word icon is activated).

Thanks for responding. I understand your confusion now that I re-read my
post along side yours. I think we are in complete agreement, my use of Word
is very different from anything you would do with Word. I am treating Word
as programming control, not an end user application, thus as control, I
don't want to muck with the user experience or environment, and as a
programmer I should the option to specify the behavior I need from Word, and
while you make good points about the user, I don't believe I made my self
clear.

I think Word and most Office Applications are broken, specifically becuase
of the test I outline, but for very different reasons.
I want to perserve any changes the user makes and I understand that
agruement, however, Word offers me functionality that would be expensive to
recreate, and thus I desire to use Word as programming control, not as an
end-user tool.

The prolem is that I want to embed Word editting power inside an authoring
application, while perserving Word's (user experience) outside of the my
application. Since MS has dropped the MDI paradigm, and yes I know "users"
where asking for this, it has made my life as application developer
impossible.

I have not been able to get anywhere with anyone at Microsoft and that is
why many Enterprise developer's still insist the Office is still not
enterprise possible.

I posted here at Microsoft's suggestion, so we will see if any developers
have ideas.

For myself, I've just completed re-engineering the winword.exe and have
found several ways around the problem I have Word, it involves some very
ugle and trick hooking of low-level windows and winword calls, but I will
get back the behavior my user's are demanding! I just means I will have to
Word version specific installs and code, but that appears to be the life of
application developer in Windows world.

Life for me and other developers would have been a lot simpler if MS would
have documented the API to winword.exe just like they have done for Internet
Explorer, where I can use IE as a control without mucking up the user
experience.

As it is, when I use Word as control I have to muck up the user experience
and that is just poor practice.


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Word Windows not working as wanted... Amy Kay General Discussion 2 June 14th, 2007 09:19 PM
multiple instances of reports Miranda Using Forms 1 September 9th, 2004 06:07 AM
Why the stumbling block when I try to Paste ? Babel17 New Users 14 July 2nd, 2004 06:23 AM
Converting 1 Word Doc to Multiple HTML Files Brian Leetch Formatting Long Documents 1 June 3rd, 2004 04:19 PM
Need a document that pops up a dialog box for user to enter info to merge Bomber Mailmerge 6 May 12th, 2004 01:45 AM


All times are GMT +1. The time now is 08:47 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.