ducmis

So I have a word.dot called VSTO-POC01.dot that has some code at startup event where it opens up a total of three exact same templates.  Now I have added a simple Window form--inside the same solution-- to open VSTO-POC01.dot when the user clicks on a button. It opens the .dot file, however it only open one .dot and stops. The other two were never processed.  Here is my code.

The code below is the code for the form with a single button to open the .dot file (is there a better way of calling the VSTO-POC01.dot  since it is sitting in the same solution )

Private Sub btnTest_Click( _

ByVal sender As System.Object, _

ByVal e As System.EventArgs _

) Handles btnTest.Click

Dim ldocWord As Word.Document

mappWord = New Word.Application

With mappWord

.Visible = True

ldocWord = mappWord.Documents.Add("D:\My Documents\Visual Studio 2005\Projects\VSTO-POC01\bin\Debug\VSTO-POC01.dot")

End With

End Sub

----------------------

 

Here is the code for the .dot file.

Public Class ThisDocument

Private Sub ThisDocument_Startup( _

ByVal sender As Object, _

ByVal e As System.EventArgs _

) Handles Me.Startup

Dim i As Int32

Dim ldocWord As Word.Document

Call MsgBox("Hello from #1")

For i = 2 To 3

Call MsgBox("Hello from #" & i.ToString)

ldocWord = Me.Application.Documents.Add("VSTO-POC01.DOT")

Next i

End Sub




Re: Visual Studio Tools for Office Form opening up a word.dot VSTO

Cindy Meister

And exactly what parts of the ThisDocument_Startup procedure do run Do yo usee the messages boxes

What happens if you put the full path in for the template in the other Documents.Add statement Mostly, Word does want the full path for this method...






Re: Visual Studio Tools for Office Form opening up a word.dot VSTO

ducmis

It opens one .dot file and displays "Hello from #1" and stops. 

Now, I tried what you suggested by adding the full path and it works. I am very happy that it works but the logic doesn't add up for me.  Word should open 3 .dot files each time the .dot file in D:\My Documents\Visual Studio 2005\Projects\VSTO-POC01\bin\Debug\VSTO-POC01.dot is open.  Accordint to the code, it should go from 2 to 3, which is two times. And each time it should give me 3 .dot files.  However, it provides me with only 3 .dot files.  This is the result that I want but my logic tells me there should be six. Why is my logic incorrect

 

so my new code looks like this

...

For i = 2 To 3

Call MsgBox("Hello from #" & i.ToString)

ldocWord = Me.Application.Documents.Add("D:\My Documents\Visual Studio 2005\Projects\VSTO-POC01\bin\Debug\VSTO-POC01.dot")

Next i

...






Re: Visual Studio Tools for Office Form opening up a word.dot VSTO

Cindy Meister

Well, if you think it through, the logic that's bothering you would actually result in an endless loop, as each new document would fire the Startup, etc. Until you ran out of memory.

However, the assembly instance is the same for all the documents, so it loads only the one time. After that, it has already started, so won't start again.






Re: Visual Studio Tools for Office Form opening up a word.dot VSTO

ducmis

Yes, after I posted my reply, I notice my logic would have an endless loop. Thanks for clarifying. You have been very helpful.