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 / Mailmerge and Fax / November 2006

Tip: Looking for answers? Try searching our database.

CommandBarComboBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
srid - 10 Nov 2006 22:40 GMT
Hi,
I am wrting a vb.net(2005) windows application with word(2003) mail merge
features. When user clicks add new template button in my windows application,
the button click events fires and opens my word template. this part is
working.

To do:
user will see a new CommandBarComboBox filled with merge fields. these merge
fields are coming from sql server 2000. when user save and close the word
application the new commandBarCombobox should get deleted from word tool bar.

PROBLEMS:
1)when I close or open the word from my application getting security
warninng to save the changes to normal.dot which I don't want to do
2)if i open word from my application ten time,there are ten
CommandBarComboBoxes on the word toolbar
3)even if i open the word seperately(not via vb.net) still i see newly
created CommandBarComboBoxes(10 or #...)
4)when user open the word template for the second time from my application,
i am getting a com error at:
 ocombo = oCommandBar.Controls.Add(MsoControlType.msoControlComboBox
I think that i am getting above error as this code is fired when i open the
form not every time i click the  cmdAddNewTemplate_Click->

Dim WithEvents ocombo As CommandBarComboBox

Question:
1)What is the best way to create a CommandBarComboBox?
2)How to stop the security warnings?
3)how to solve above problems(4)?

Here is my code:

Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word
Imports System.Runtime.InteropServices 'capture the COM errors
Imports Microsoft.Office.Core

'class
public Class Mailmerge

Dim WithEvents ocombo As CommandBarComboBox
Dim WithEvents wordApp As Word.Application

'click event
Private Sub cmdAddNewTemplate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdAddNewTemplate.Click

       'define CommandBarControl
       'Dim comBarControl As CommandBarControl = Nothing
       'define office commandbar
       Dim oCommandBar As CommandBar = Nothing

       'ocombo = Core.CommandBarComboBox
       wordApp = New Word.Application
       Dim oMainDoc As New Word.Document

       'Start a new main document for  mail merge ;assign the word template
path
       oMainDoc = wordApp.Documents.Add("C:\word Template\mytemplate.frm")
       wordApp.Visible = True

       ' Create a new command bar.
      ocombo = oCommandBar.Controls.Add(MsoControlType.msoControlComboBox)
       
       ' Add items to the combo box.

       ocombo.AddItem("FirstName")

       ocombo.AddItem("LastName")

       ocombo.AddItem("Dear")

       ' Set the caption and style.

       ocombo.Caption = "Select the merge fields:"

       ocombo.Style = MsoComboStyle.msoComboLabel

       ' Show the command bar to the user.
       oCommandBar.Visible = True

       'AddWordToolbar()
       'wordApp = Nothing

End Sub

'combobox change event
'insert merge field
Private Sub oCombo_Change(ByVal Ctrl As CommandBarComboBox) Handles
ocombo.Change

 Dim wrdSelection As Word.Selection = wordApp.Application.Selection

wordApp.ActiveDocument.MailMerge.Fields.Add(wrdSelection.Range,
Name:=ocombo.Text)

End Sub

end class
'===

thanks in advance.
Doug Robbins - Word MVP - 11 Nov 2006 00:36 GMT
Instead of using a CommandBarComboBox, have the code in your template open a
UserForm that contains a list box that is populated with the mergefields.

Such a userform is used in the addin that you can download from:

http://www.gmayor.com/individual_merge_letters.htm

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi,
> I am wrting a vb.net(2005) windows application with word(2003) mail merge
[quoted text clipped - 105 lines]
>
> thanks in advance.
srid - 11 Nov 2006 18:28 GMT
thanks for the info.
let me give it a try

> Instead of using a CommandBarComboBox, have the code in your template open a
> UserForm that contains a list box that is populated with the mergefields.
[quoted text clipped - 112 lines]
> >
> > thanks in advance.
 
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.