Lost Menu and toolbars after office automation?

  • Thread starter Paul Ruedisueli
  • Start date
P

Paul Ruedisueli

Hello,

I am creating an application that uses word templates and a database for
mail merge.
If the template used has Fill-in fields all the menu's and toolbars are gone
after when i activate Word.

This is the code i use:

Dim vlobjWord As New Microsoft.Office.Interop.Word.Application

vlobjWord.Documents.Open(vlcFileName)
vlobjWord.ActiveDocument.Activate()

vlobjWord.ActiveDocument.MailMerge.OpenDataSource(vlcTempDir &
"\mailing_records.mdb")
vlobjWord.ActiveDocument.MailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument
vlobjWord.ActiveDocument.MailMerge.Execute()
vlobjWord.Documents(vlobjWord.Documents.Count).Close(False)

vlobjWord.Visible = True

Please assist.
 
C

Cindy M.

Hi Paul,

Which version of Word are we dealing with, here?

If you do the following, do you see different behavior:

Dim vlobjWord As Microsoft.Office.Interop.Word.Application _
= New Microsoft.Office.Interop.Word.Application

vlobjWord.Activate
vlobjWord.Visible = True
Dim doc as Microsoft.Office.Interop.Word.Document _
= vlobjWord.Documents.Open(vlcFileName)
doc.MailMerge.OpenDataSource( _
vlcTempDir & "\mailing_records.mdb")
'and so on
I am creating an application that uses word templates and a database for
mail merge.
If the template used has Fill-in fields all the menu's and toolbars are gone
after when i activate Word.

This is the code i use:

Dim vlobjWord As New Microsoft.Office.Interop.Word.Application

vlobjWord.Documents.Open(vlcFileName)
vlobjWord.ActiveDocument.Activate()

vlobjWord.ActiveDocument.MailMerge.OpenDataSource(vlcTempDir &
"\mailing_records.mdb")
vlobjWord.ActiveDocument.MailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument
vlobjWord.ActiveDocument.MailMerge.Execute()
vlobjWord.Documents(vlobjWord.Documents.Count).Close(False)

vlobjWord.Visible = True

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 
P

Paul Ruedisueli

Hi Cindy,

Both Word 2003 and Word 2007.

No there is no difference when i use your example. It only happens if the
template has Fill-In Fields embedded. Al other template work great.

Please help

Paul Ruedisueli
 
C

Cindy M.

Hi =?Utf-8?B?UGF1bCBSdWVkaXN1ZWxp?=,
Both Word 2003 and Word 2007.

No there is no difference when i use your example. It only happens if the
template has Fill-In Fields embedded. Al other template work great.
Try switching Visible and Activate (the order). And maybe stick a DoEvents
in there before opening the document.

There is a problem with Word in some circumstances where things don't finish
loading. I'm pretty sure the display of these fields is what's interrupting
things, so the key will be to make sure Word finishes before the document is
opened.

Worst case: you have to LOCK the field codes in the main merge document so
that they can't update automatically (or use ASK fields that won't display
automatically). Then your code unlocks and updates the fields after the
document has been opened.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 
P

Paul Ruedisueli

Hello Cindy,

First of all, Thank you for your help.

The problem persists when i change to order of Activate and visible.

When i lock the fields i get an error stating that, during the merge, fields
where locked and could not be updated.

Maybe i should be more clear what happens.

I open a word-template which has FillIn Fields in it.
I then Merge this template with data from a msacces database to a new
document.
I then display this last document.

When i display the last document to complete top of Word is missing (no
window header bar, no menu bar no toolbar). Try it your self and you wil see.

Thanks in advance,

Paul Ruedisueli
 
C

Cindy M.

Hi =?Utf-8?B?UGF1bCBSdWVkaXN1ZWxp?=,
When i lock the fields i get an error stating that, during the merge, fields
where locked and could not be updated.
You need to then UNLOCK the fields after the document has been opened:

1. Design the document - lock the fields
2. VBA starts the Word application (Visible and Active!), opens the document
(Visible, fields are locked - should be no problems)
3. Unlock the fields (Document.Fields.Locked = False)
4. Execute the merge (the Fillin fields should display as part of the merge)

The resulting merge document should be the ActiveDocument (and visible) at this
point (default Word behavior).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 

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