tecla
Erfahrenes Mitglied
Salut zusammen
Ich hab mit Visual Studio Tools for Office (VSTO) eine WordTemplate-Projekt.
Im Startup-Event kreiere ich einen Button im ActionsPane und ein eigenes Menü mit Kommandos drin.
Öffne ich die dot-Datei aus dem VSTO heraus, macht er mir brav eine Kopie (Dokument1) und darin erscheinen mein Menü und die Dokumentaktionen mit Knopf, super.
Wenn ich jetzt aber das Visual Studio schliesse und die dot-Datei mit Doppelklick öffne, erscheinen weder Menü noch Dokumentaktionen.
Ich habs auch noch mit einem zusätzlichen this.new - Event versucht, ebenfalls nix.
Wiese läuft der Code behind nicht ab? Irgendwas scheine ich nicht kapiert oder vergessen zu haben und wäre sehr froh um ein wenig Info zu diesem Thema.
Anbei ein bisschen Code:
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
namespace ProDOT
{
public partial class ThisDocument
{
private Office.CommandBarButton menuCommand;
private string menuTag = "A unique tag";
Button meinKnopf = new Button();
DataTable table;
private void ThisDocument_Startup(object sender, System.EventArgs e)
{
this.New += new Microsoft.Office.Interop.Word.DocumentEvents2_NewEventHandler(ThisDocument_New);
}
void ThisDocument_New()
{
CheckIfMenuBarExists();
AddMenuBar();
meinKnopf.Text = "HalloDataTable";
meinKnopf.Click += new EventHandler(meinKnopf_Click);
ActionsPane.Controls.Add(meinKnopf);
}
private void AddMenuBar()
{
try
{
Office.CommandBarPopup cmdBarControl = null;
Office.CommandBar menuBar = (Office.CommandBar)Application.CommandBars.ActiveMenuBar;
int controlCount = menuBar.Controls.Count;
string menucaption = "Hallo Ich neues Menu";
cmdBarControl = (Office.CommandBarPopup)menuBar.Controls.Add(
Office.MsoControlType.msoControlPopup, missing, missing, controlCount, true);
if (cmdBarControl != null)
{
cmdBarControl.Caption = menucaption;
menuCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add(
Office.MsoControlType.msoControlButton, missing, missing, missing, true);
menuCommand.Caption = "Knopf1";
menuCommand.Tag = "1Knopf1";
menuCommand.FaceId = 65;
menuCommand.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand_Click);
}
}
catch (Exception e)
{
MessageBox.Show("Fehler2 " + e.Message);
}
}
private void menuCommand_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
{
MessageBox.Show("Der Super Knopf läuft ohne Fehler!");
}
void CheckIfMenuBarExists()
{
try
{
Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
this.Application.CommandBars.ActiveMenuBar.FindControl(
Office.MsoControlType.msoControlPopup, missing, missing, true, true);
if (foundMenu != null)
{
foundMenu.Delete(true);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void meinKnopf_Click(object sender, EventArgs e)
{
MessageBox.Show("Die Dokumentaktionen funktionieren wunderbar!");
}
Ich hab mit Visual Studio Tools for Office (VSTO) eine WordTemplate-Projekt.
Im Startup-Event kreiere ich einen Button im ActionsPane und ein eigenes Menü mit Kommandos drin.
Öffne ich die dot-Datei aus dem VSTO heraus, macht er mir brav eine Kopie (Dokument1) und darin erscheinen mein Menü und die Dokumentaktionen mit Knopf, super.
Wenn ich jetzt aber das Visual Studio schliesse und die dot-Datei mit Doppelklick öffne, erscheinen weder Menü noch Dokumentaktionen.
Ich habs auch noch mit einem zusätzlichen this.new - Event versucht, ebenfalls nix.
Wiese läuft der Code behind nicht ab? Irgendwas scheine ich nicht kapiert oder vergessen zu haben und wäre sehr froh um ein wenig Info zu diesem Thema.
Anbei ein bisschen Code:
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
namespace ProDOT
{
public partial class ThisDocument
{
private Office.CommandBarButton menuCommand;
private string menuTag = "A unique tag";
Button meinKnopf = new Button();
DataTable table;
private void ThisDocument_Startup(object sender, System.EventArgs e)
{
this.New += new Microsoft.Office.Interop.Word.DocumentEvents2_NewEventHandler(ThisDocument_New);
}
void ThisDocument_New()
{
CheckIfMenuBarExists();
AddMenuBar();
meinKnopf.Text = "HalloDataTable";
meinKnopf.Click += new EventHandler(meinKnopf_Click);
ActionsPane.Controls.Add(meinKnopf);
}
private void AddMenuBar()
{
try
{
Office.CommandBarPopup cmdBarControl = null;
Office.CommandBar menuBar = (Office.CommandBar)Application.CommandBars.ActiveMenuBar;
int controlCount = menuBar.Controls.Count;
string menucaption = "Hallo Ich neues Menu";
cmdBarControl = (Office.CommandBarPopup)menuBar.Controls.Add(
Office.MsoControlType.msoControlPopup, missing, missing, controlCount, true);
if (cmdBarControl != null)
{
cmdBarControl.Caption = menucaption;
menuCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add(
Office.MsoControlType.msoControlButton, missing, missing, missing, true);
menuCommand.Caption = "Knopf1";
menuCommand.Tag = "1Knopf1";
menuCommand.FaceId = 65;
menuCommand.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand_Click);
}
}
catch (Exception e)
{
MessageBox.Show("Fehler2 " + e.Message);
}
}
private void menuCommand_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
{
MessageBox.Show("Der Super Knopf läuft ohne Fehler!");
}
void CheckIfMenuBarExists()
{
try
{
Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
this.Application.CommandBars.ActiveMenuBar.FindControl(
Office.MsoControlType.msoControlPopup, missing, missing, true, true);
if (foundMenu != null)
{
foundMenu.Delete(true);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void meinKnopf_Click(object sender, EventArgs e)
{
MessageBox.Show("Die Dokumentaktionen funktionieren wunderbar!");
}