View Single Post
  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
srid srid is offline
external usenet poster
 
Posts: 15
Default how to create word CommandBarComboBox using vb.net(automate word)

thanks for asking cindy. still i am looking for help.

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 #...)

Question:
1)What is the best way to create a CommandBarComboBox with data in vb.net?
2)there are 995 user created templates. merge fields are tagged as
{{fieldname}}. how to change them to word 2003 merge fields?
I tried to replace them with fieldname or {mergefield "fieldname"} but
word is not recognizing them as merge fiels.

if you can pls provide some details

thanks in advance



"srid" wrote:

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.msoControl ComboBox
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.msoControl ComboBox)

' 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(wrdSel ection.Range,
Name:=ocombo.Text)

End Sub

end class
'===

thanks in advance.