Code Snippets


Clipboard_Clear

public void Clipboard_Clear()
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(),
false
);

mClipboardObject = null;
}

CmdBar_ButtonAdd

public Office.CommandBarButton CmdBar_ButtonAdd(
string sBarName,
string sButtonParameter,
string sButtonTag,
string sButtonOnAction,
string sButtonCaption,
string sButtonToolTip = "",
bool bBeginGroup = false,
int iButtonFaceID = 0,
bool bPasteFace = false,
int iButtonWidth = 10,
bool bSelected = false,
bool bTemporary = false,
bool bShortcutMenu = false,
bool bResetClipboard = true)
{
Office.CommandBar objCommandBar = null;
Office.CommandBarButton objButton = null;

Office.CommandBarButton returnValue = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonAdd");
return null;
}

// === Create the button ===
if (!bShortcutMenu)
{
objButton = (Office.CommandBarButton)mCommandBars[sBarName].Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sButtonParameter);
}
else
{
// Search popup shortcut menus by name
for (int i = 1; i <= mCommandBars.Count; i++)
{
if (mCommandBars[i].Type == Office.MsoBarType.msoBarTypePopup &&
mCommandBars[i].Name == sBarName)
{
objButton = (Office.CommandBarButton)mCommandBars[i].Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sButtonParameter);
break;
}
}
}

// === Configure the button ===
if (!bPasteFace && iButtonFaceID == 0)
{
objButton.Style = Office.MsoButtonStyle.msoButtonCaption;
}
if (bPasteFace || iButtonFaceID > 0)
{
objButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
}

objButton.Tag = sButtonTag;
objButton.OnAction = sButtonOnAction;
objButton.Caption = sButtonCaption;
objButton.TooltipText = sButtonToolTip;
objButton.BeginGroup = bBeginGroup;
objButton.Width = iButtonWidth;

// === Face handling ===
if (!bPasteFace && iButtonFaceID > 0)
{
objButton.FaceId = iButtonFaceID;
}

if (bPasteFace)
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false);
}
}

// === Button state ===
objButton.State = bSelected
? Office.MsoButtonState.msoButtonDown
: Office.MsoButtonState.msoButtonUp;

returnValue = objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objCommandBar = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonAdd",
msCLASSNAME,
"add the button with" + gsCRLF +
"Caption: '" + sButtonCaption + "'" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ButtonAddFaceOnly

public Office.CommandBarButton CmdBar_ButtonAddFaceOnly(
string sBarName,
string sButtonParameter,
string sButtonTag,
string sButtonOnAction,
string sButtonToolTip = "",
bool bBeginGroup = false,
int iButtonFaceID = 0,
bool bPasteFace = false,
int iButtonWidth = 20,
bool bTemporary = false,
bool bResetClipboard = true)
{
Office.CommandBarButton objButton = null;
Office.CommandBarButton returnValue = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonAddFaceOnly");
return null;
}

objButton = (Office.CommandBarButton)mCommandBars[sBarName].Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sButtonParameter);

// === Configure the button ===
objButton.Style = Office.MsoButtonStyle.msoButtonIcon;
objButton.Tag = sButtonTag;
objButton.OnAction = sButtonOnAction;
objButton.TooltipText = sButtonToolTip;
objButton.BeginGroup = bBeginGroup;
objButton.Width = iButtonWidth;

// === Face handling ===
if (!bPasteFace && iButtonFaceID > 0)
{
objButton.FaceId = iButtonFaceID;
}

if (bPasteFace)
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false);
}
}

returnValue = objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonAddFaceOnly",
msCLASSNAME,
"add the 'face only' button with" +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ButtonCaptionChange

public void CmdBar_ButtonCaptionChange(
string sBarName,
string sButtonParameter,
string sButtonCaptionExisting,
string sButtonCaptionNew)
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonCaptionChange");
return;
}

Office.CommandBar bar = mCommandBars[sBarName];

// === Search by Parameter ===
if (sButtonParameter.Length > 0)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}
}

// === Search by existing Caption ===
if (objButton == null && sButtonCaptionExisting.Length > 0)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Caption == sButtonCaptionExisting)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}
}

// === Apply new caption ===
if (objButton != null)
{
objButton.Caption = sButtonCaptionNew;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonCaptionChange",
msCLASSNAME,
"change the caption on the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"Caption: '" + sButtonCaptionExisting + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ButtonCaptionGet

public string CmdBar_ButtonCaptionGet(
string sBarName,
string sButtonParameter)
{
Office.CommandBarButton objButton = null;
string returnValue = string.Empty;

try
{
if (gbEND_GENERAL)
return string.Empty;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonCaptionGet");
return string.Empty;
}

Office.CommandBar bar = mCommandBars[sBarName];

// Search by Parameter (1-based enumeration)
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}

if (objButton != null)
{
returnValue = objButton.Caption;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonCaptionGet",
msCLASSNAME,
"return the caption from the button with" + gsCRLF +
"Parameter '" + sButtonParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ButtonDelete

public void CmdBar_ButtonDelete(
string sBarName,
string sButtonParameter,
string sButtonTag,
string sButtonCaption = "",
int iButtonID = -1)
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonDelete");
return;
}

Office.CommandBar bar = mCommandBars[sBarName];

// Search by Parameter (1-based enumeration)
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}

// Delete the button (VBA assumes objButton is not Nothing)
objButton?.Delete();
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonDelete",
msCLASSNAME,
"delete the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"Tag: '" + sButtonTag + "'" + gsCRLF +
"Caption: '" + sButtonCaption + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ButtonEnabledChange

public void CmdBar_ButtonEnabledChange(
string sBarName,
string sButtonParameter,
string sButtonTag,
string sButtonCaption,
bool bEnable,
int iButtonID = -1)
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonEnabledChange");
return;
}

Office.CommandBar bar = mCommandBars[sBarName];

// === Search logic (Parameter OR ID) ===
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (iButtonID == -1)
{
// Search by Parameter
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}
else
{
// Search by ID
if (bar.Controls[i].Id == iButtonID)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}
}

// === Apply enabled state ===
if (objButton != null)
{
objButton.Enabled = bEnable;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonEnabledChange",
msCLASSNAME,
"enable or disable the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"Tag: '" + sButtonTag + "'" + gsCRLF +
"Caption: '" + sButtonCaption + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ButtonEnabledGet

public bool CmdBar_ButtonEnabledGet(
string sBarName,
string sButtonParameter,
string sButtonTag,
string sButtonCaption = "",
int iButtonID = -1)
{
Office.CommandBarButton objButton = null;
bool returnValue = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonEnabledGet");
return false;
}

Office.CommandBar bar = mCommandBars[sBarName];

// === Search by Parameter (only if Caption is empty) ===
if (sButtonCaption.Length == 0)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}
}

// === Search by Caption (only if Parameter is empty) ===
if (objButton == null && sButtonParameter.Length == 0)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Caption == sButtonCaption)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}
}

if (objButton != null)
{
returnValue = objButton.Enabled;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonEnabledGet",
msCLASSNAME,
"determine whether the button with" + gsCRLF +
"Parameter '" + sButtonParameter + "'" + gsCRLF +
"Tag '" + sButtonTag + "'" + gsCRLF +
"Caption '" + sButtonCaption + "'" + gsCRLF +
"is enabled or disabled" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ButtonExists

public bool CmdBar_ButtonExists(
string sBarName,
string sButtonParameter,
string sButtonTag,
string sButtonCaption = "")
{
Office.CommandBarButton objButton = null;
bool returnValue = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonExists");
return false;
}

Office.CommandBar bar = mCommandBars[sBarName];

// === Search by Parameter ===
if (sButtonParameter.Length > 0)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}
}

// === Search by Caption ===
if (objButton == null && sButtonCaption.Length > 0)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Caption == sButtonCaption)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}
}

returnValue = (objButton != null);
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonExists",
msCLASSNAME,
"determine if the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"Tag: '" + sButtonTag + "'" + gsCRLF +
"Caption: '" + sButtonCaption + "'" + gsCRLF +
"exists on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ButtonFaceChange

public void CmdBar_ButtonFaceChange(
string sBarName,
int iButtonID,
string sButtonParameter,
string sButtonTag,
string sButtonCaption,
int iButtonFaceID,
bool bPasteFace = false,
bool bResetClipboard = true)
{
Office.CommandBar objCommandBar = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonFaceChange");
return;
}

objCommandBar = mCommandBars[sBarName];

// === Search by Parameter ===
if (sButtonParameter.Length > 0)
{
for (int i = 1; i <= objCommandBar.Controls.Count; i++)
{
if (objCommandBar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)objCommandBar.Controls[i];
break;
}
}
}

// === Search by ID ===
if (iButtonID > -1)
{
for (int i = 1; i <= objCommandBar.Controls.Count; i++)
{
if (objCommandBar.Controls[i].Id == iButtonID)
{
objButton = (Office.CommandBarButton)objCommandBar.Controls[i];
break;
}
}
}

// === Search by Caption ===
if (sButtonCaption.Length > 0)
{
for (int i = 1; i <= objCommandBar.Controls.Count; i++)
{
if (objCommandBar.Controls[i].Caption == sButtonCaption)
{
objButton = (Office.CommandBarButton)objCommandBar.Controls[i];
break;
}
}
}

// === Apply face changes ===
if (objButton != null)
{
if (!bPasteFace && iButtonFaceID > 0)
{
objButton.FaceId = iButtonFaceID;
}

if (bPasteFace)
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false);
}
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objCommandBar = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonFaceChange",
msCLASSNAME,
"change the face of the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"Tag: '" + sButtonTag + "'" + gsCRLF +
"ID: '" + iButtonID + "'" + gsCRLF +
"Caption: '" + sButtonCaption + "'" + gsCRLF +
"to a button with" + gsCRLF +
"ID: " + iButtonFaceID + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ButtonFaceCopyFromFile

public void CmdBar_ButtonFaceCopyFromFile(
string sFolderPath,
string sFileName)
{
try
{
if (gbEND_GENERAL)
return;

// Save current clipboard contents
mClipboardObject = System.Windows.Forms.Clipboard.GetDataObject();

// Create a new DataObject containing the bitmap
var dataObject = new System.Windows.Forms.DataObject();
dataObject.SetData(
"Bitmap",
System.Drawing.Image.FromFile(sFolderPath + sFileName));

// Replace clipboard contents
System.Windows.Forms.Clipboard.SetDataObject(dataObject);
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonFaceCopyFromFile",
msCLASSNAME,
"copy the Face ID from the file" + gsCRLF +
"'" + sFolderPath + sFileName + "'" + gsCRLF +
"and place it on the clipboard.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ButtonFaceCopyFromImageList

public void CmdBar_ButtonFaceCopyFromImageList(
string sImageListName,
System.Windows.Forms.ImageList objImageList,
int iImageIndexNo)
{
try
{
if (gbEND_GENERAL)
return;

// Save current clipboard contents
mClipboardObject = System.Windows.Forms.Clipboard.GetDataObject();

// Create a new DataObject containing the bitmap
var dataObject = new System.Windows.Forms.DataObject();
dataObject.SetData("Bitmap", objImageList.Images[iImageIndexNo]);

// Replace clipboard contents
System.Windows.Forms.Clipboard.SetDataObject(dataObject);
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonFaceCopyFromImageList",
msCLASSNAME,
"copy image number '" + iImageIndexNo + "'" + gsCRLF +
"from the imagelist '" + sImageListName + "'" + gsCRLF +
"and place it on the clipboard.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ButtonInsert

public Office.CommandBarButton CmdBar_ButtonInsert(
string sBarName,
int iBeforeControlID,
string sBeforeControlParameter,
string sBeforeControlTag,
string sBeforeControlCaption,
string sButtonParameter,
string sButtonTag,
string sButtonOnAction,
string sButtonCaption,
string sButtonToolTip = "",
bool bBeginGroup = false,
int iButtonFaceID = 0,
bool bPasteFace = false,
int iButtonWidth = 10,
bool bSelected = false,
bool bTemporary = false,
bool bShortcutMenu = false,
bool bResetClipboard = true)
{
Office.CommandBar objCommandBar = null;
Office.CommandBarButton objButton = null;
Office.CommandBarButton returnValue = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonInsert");
return null;
}

objCommandBar = mCommandBars[sBarName];

int beforeIndex = 1;

// === Determine insertion point ===
for (int i = 1; i <= objCommandBar.Controls.Count; i++)
{
if (iBeforeControlID > 0 &&
objCommandBar.Controls[i].Id == iBeforeControlID)
{
beforeIndex = i;
break;
}

if (sBeforeControlParameter.Length > 0 &&
objCommandBar.Controls[i].Parameter == sBeforeControlParameter)
{
beforeIndex = i;
break;
}

if (sBeforeControlCaption.Length > 0 &&
objCommandBar.Controls[i].Caption == sBeforeControlCaption)
{
beforeIndex = i;
break;
}
}

// === Create the button ===
if (!bShortcutMenu)
{
objButton = (Office.CommandBarButton)objCommandBar.Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Before: beforeIndex,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sButtonParameter);
}
else
{
// Find popup bar with matching name
for (int i = 1; i <= mCommandBars.Count; i++)
{
if (mCommandBars[i].Type == Office.MsoBarType.msoBarTypePopup &&
mCommandBars[i].Name == sBarName)
{
objButton = (Office.CommandBarButton)objCommandBar.Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Before: beforeIndex,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sButtonParameter);
break;
}
}
}

// === Configure the button ===
if (!bPasteFace && iButtonFaceID == 0)
{
objButton.Style = Office.MsoButtonStyle.msoButtonCaption;
}
if (bPasteFace || iButtonFaceID > 0)
{
objButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
}

objButton.Tag = sButtonTag;
objButton.OnAction = sButtonOnAction;
objButton.Caption = sButtonCaption;
objButton.TooltipText = sButtonToolTip;
objButton.BeginGroup = bBeginGroup;
objButton.Width = iButtonWidth;

// === Face handling ===
if (!bPasteFace && iButtonFaceID > 0)
{
objButton.FaceId = iButtonFaceID;
}

if (bPasteFace)
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false);
}
}

// === State ===
objButton.State = bSelected
? Office.MsoButtonState.msoButtonDown
: Office.MsoButtonState.msoButtonUp;

returnValue = objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objCommandBar = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonInsert",
msCLASSNAME,
"insert the button with" + gsCRLF +
"Caption: '" + sButtonCaption + "'" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ButtonReturn

public Office.CommandBarButton CmdBar_ButtonReturn(
string sBarName,
string sButtonParameter,
string sButtonTag,
string sButtonCaption = "",
int iButtonID = -1)
{
Office.CommandBarButton objButton = null;
Office.CommandBarButton returnValue = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonReturn");
return null;
}

Office.CommandBar bar = mCommandBars[sBarName];

// Search by Parameter (1-based enumeration)
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}

returnValue = objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonReturn",
msCLASSNAME,
"return the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ButtonStateChange

public void CmdBar_ButtonStateChange(
string sBarName,
string sButtonParameter,
string sButtonCaption,
bool bSelected,
string sButtonTag = "")
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonStateChange");
return;
}

Office.CommandBar bar = mCommandBars[sBarName];

// Search by Parameter (1-based enumeration)
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}

// Apply state change
if (objButton != null)
{
objButton.State = bSelected
? Office.MsoButtonState.msoButtonDown
: Office.MsoButtonState.msoButtonUp;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonStateChange",
msCLASSNAME,
"change the state of the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ButtonStateGet

public bool CmdBar_ButtonStateGet(
string sBarName,
string sButtonParameter,
string sButtonCaption = "",
string sButtonTag = "")
{
Office.CommandBarButton objButton = null;
bool returnValue = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonStateGet");
return false;
}

Office.CommandBar bar = mCommandBars[sBarName];

// Search by Parameter (1-based enumeration)
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}

if (objButton != null)
{
returnValue =
objButton.State == Office.MsoButtonState.msoButtonDown;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonStateGet",
msCLASSNAME,
"return the state of the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ButtonToolTipChange

public void CmdBar_ButtonToolTipChange(
string sBarName,
string sButtonParameter,
string sButtonCaption,
string sButtonToolTip,
string sButtonTag = "")
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ButtonToolTipChange");
return;
}

Office.CommandBar bar = mCommandBars[sBarName];

// Search by Parameter (1-based enumeration)
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}

if (objButton != null)
{
objButton.TooltipText = sButtonToolTip;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonToolTipChange",
msCLASSNAME,
"change the tooltip text for the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_CheckBoxAdd

public Office.CommandBarButton CmdBar_CheckBoxAdd(
string sBarName,
string sCheckboxParameter,
string sCheckboxTag,
string sCheckboxOnAction,
string sCheckboxCaption,
bool bSelected = false,
bool bBeginGroup = false,
int iCheckboxFaceID = 0,
bool bTemporary = false)
{
Office.CommandBarButton objButton = null;
Office.CommandBarButton returnValue = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("CheckBoxAdd");
return null;
}

objButton = (Office.CommandBarButton)mCommandBars[sBarName].Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sCheckboxParameter);

// --- Assign properties exactly as in VBA ---
objButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
objButton.Tag = sCheckboxTag;
objButton.Caption = sCheckboxCaption;
objButton.OnAction = sCheckboxOnAction;
objButton.BeginGroup = bBeginGroup;

if (iCheckboxFaceID == 0)
{
if (bSelected)
{
objButton.FaceId = giCHECKBOX_FACEID;
objButton.State = Office.MsoButtonState.msoButtonDown;
}
else
{
objButton.FaceId = 1;
objButton.State = Office.MsoButtonState.msoButtonUp;
}
}
else
{
objButton.FaceId = iCheckboxFaceID;
}

returnValue = objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"CheckBoxAdd",
msCLASSNAME,
"add the checkbox with" + gsCRLF +
"Parameter: '" + sCheckboxParameter + "'" + gsCRLF +
"Caption: '" + sCheckboxCaption + "'" + gsCRLF +
"Tag: '" + sCheckboxTag + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_CheckBoxChange

public void CmdBar_CheckBoxChange(
string sBarName,
string sCheckBoxParameter,
string sCheckBoxCaption,
bool bSelected,
string sCheckBoxTag = "")
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (sCheckBoxParameter == "DontChange")
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("CheckBoxChange");
return;
}

// --- Locate the checkbox by Parameter (1-based enumeration) ---
Office.CommandBar bar = mCommandBars[sBarName];
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sCheckBoxParameter)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}

// --- Apply checkbox state ---
if (bSelected)
{
objButton.FaceId = giCHECKBOX_FACEID;
objButton.State = Office.MsoButtonState.msoButtonDown;
}
else
{
objButton.FaceId = 1;
objButton.State = Office.MsoButtonState.msoButtonUp;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"CheckBoxChange",
msCLASSNAME,
"change the checkbox with" + gsCRLF +
"Parameter: '" + sCheckBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_CheckBoxInsert

public Office.CommandBarButton CmdBar_CheckBoxInsert(
string sBarName,
string sBeforeControlParameter,
string sBeforeControlTag,
string sBeforeControlCaption,
string sCheckboxParameter,
string sCheckboxTag,
string sCheckboxOnAction,
string sCheckboxCaption,
bool bSelected = false,
bool bBeginGroup = false,
int iCheckboxFaceID = 0,
bool bTemporary = false)
{
Office.CommandBar objCommandBar = null;
Office.CommandBarButton objButton = null;
Office.CommandBarButton returnValue = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("CheckBoxInsert");
return null;
}

objCommandBar = mCommandBars[sBarName];

// --- Find the BEFORE position by Caption (1-based) ---
int iBeforeControlNo;
for (iBeforeControlNo = 1; iBeforeControlNo <= objCommandBar.Controls.Count; iBeforeControlNo++)
{
if (objCommandBar.Controls[iBeforeControlNo].Caption == sBeforeControlCaption)
break;
}

// --- Insert the new checkbox button ---
objButton = (Office.CommandBarButton)objCommandBar.Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Before: iBeforeControlNo,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sCheckboxParameter);

// --- Assign properties exactly as in VBA ---
objButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
objButton.Tag = sCheckboxTag;
objButton.Caption = sCheckboxCaption;
objButton.OnAction = sCheckboxOnAction;
objButton.BeginGroup = bBeginGroup;

if (iCheckboxFaceID == 0)
{
if (bSelected)
{
objButton.FaceId = giCHECKBOX_FACEID;
objButton.State = Office.MsoButtonState.msoButtonDown;
}
else
{
objButton.FaceId = 1;
objButton.State = Office.MsoButtonState.msoButtonUp;
}
}
else
{
objButton.FaceId = iCheckboxFaceID;
}

returnValue = objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"CheckBoxInsert",
msCLASSNAME,
"insert the checkbox with" + gsCRLF +
"Parameter: '" + sCheckboxParameter + "'" + gsCRLF +
"Caption: '" + sCheckboxCaption + "'" + gsCRLF +
"Tag: '" + sCheckboxTag + "'" + gsCRLF +
"before the control with" + gsCRLF +
"Caption: '" + sBeforeControlCaption + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ComboBoxAdd

public Office.CommandBarComboBox CmdBar_ComboBoxAdd(
string sBarName,
string sComboBoxParameter,
string sComboBoxTag,
string sComboBoxToolTip = "",
int iComboBoxWidth = 50,
bool bBeginGroup = false,
int iComboBoxNoofDropLines = 10,
bool bTemporary = false)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxAdd");
return null;
}

objComboBox = (Office.CommandBarComboBox)mCommandBars[sBarName].Controls.Add(
Type: Office.MsoControlType.msoControlComboBox,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sComboBoxParameter
);

objComboBox.Tag = sComboBoxTag;
objComboBox.Width = iComboBoxWidth;
objComboBox.TooltipText = sComboBoxToolTip;
objComboBox.BeginGroup = bBeginGroup;
objComboBox.DropDownLines = iComboBoxNoofDropLines;
objComboBox.ListIndex = 0;

return objComboBox;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxAdd",
msCLASSNAME,
"add the combo box with" + gsCRLF +
"Parameter '" + sComboBoxParameter + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return null;
}

CmdBar_ComboBoxAddFiles

public void CmdBar_ComboBoxAddFiles(
string sBarName,
string sComboBoxParameter,
string sFolderPath,
string sSearchPattern,
bool bSelectSingle = true,
bool bDisplayCount = false)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxAddFiles");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

objComboBox.Clear();

// Get files
string[] files = System.IO.Directory.GetFiles(sFolderPath, sSearchPattern);

int count = files.Length;

// Add filenames
for (int i = 0; i < count; i++)
{
string fileName = new System.IO.FileInfo(files[i]).Name;

if (fileName.Length > 0)
objComboBox.AddItem(fileName);
}

// Post-population rules
if (count == 0)
{
objComboBox.AddItem("(none)");
objComboBox.ListIndex = 1;
}
else if (count == 1 && bSelectSingle)
{
objComboBox.ListIndex = 1;
}
else if (count > 1 && bDisplayCount)
{
objComboBox.AddItem("(" + objComboBox.ListCount + " files)", Index: 1);
objComboBox.ListIndex = 1;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxAddFiles",
msCLASSNAME,
"add all the files in the folder" + gsCRLF +
"'" + sFolderPath + "'" + gsCRLF +
"to the combo box with " + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxAddString

public void CmdBar_ComboBoxAddString(
string sBarName,
string sComboBoxParameter,
string sComboBoxTextConCat,
string sSeparateChar = ";",
bool bClearComboBox = true)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxAddString");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

if (bClearComboBox)
objComboBox.Clear();

// Manual parsing loop — preserves VBA behaviour exactly
while (sComboBoxTextConCat.Length > 0)
{
int pos = Microsoft.VisualBasic.Strings.InStr(
1,
sComboBoxTextConCat,
sSeparateChar
);

string nextEntry;

if (pos == 0)
{
nextEntry = sComboBoxTextConCat;
sComboBoxTextConCat = "";
}
else
{
nextEntry = Microsoft.VisualBasic.Strings.Left(
sComboBoxTextConCat,
pos - 1
);

sComboBoxTextConCat = Microsoft.VisualBasic.Strings.Right(
sComboBoxTextConCat,
sComboBoxTextConCat.Length - nextEntry.Length - 1
);
}

objComboBox.AddItem(Text: nextEntry);
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxAddString",
msCLASSNAME,
"add the string concatenation" + gsCRLF +
"'" + sComboBoxTextConCat + "'" + gsCRLF +
"to the combo box with" + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxAddTextFile

public void CmdBar_ComboBoxAddTextFile(
string sBarName,
string sComboBoxParameter,
string sFolderPath,
string sFileName,
string sFileExtension)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxAddTextFile");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

objComboBox.Clear();

// Add code to get from textfile (not implemented in original VBA)
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxAddTextFile",
msCLASSNAME,
"add all the lines from the text file" + gsCRLF +
"'" + sFolderPath + sFileName + sFileExtension + "'" + gsCRLF +
"to the combobox with" + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxClear

public void CmdBar_ComboBoxClear(
string sBarName,
string sComboBoxParameter)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxClear");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

objComboBox.Clear();
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxClear",
msCLASSNAME,
"clear all the entries in the combobox with" + gsCRLF +
"Parameter '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxDropDownLinesChange

public void CmdBar_ComboBoxDropDownLinesChange(
string sBarName,
string sComboBoxParameter,
int iNoofDropDownLines)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxDropDownLinesChange");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

objComboBox.DropDownLines = iNoofDropDownLines;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxDropDownLinesChange",
msCLASSNAME,
"change the number of drop-down lines of the combobox with" + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxEnabledChange

public void CmdBar_ComboBoxEnabledChange(
string sBarName,
string sComboBoxParameter,
bool bEnable)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxEnabledChange");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

objComboBox.Enabled = bEnable;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxEnabledChange",
msCLASSNAME,
"enable or disable the combobox with" + gsCRLF +
"Parameter '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxItemInsert

public void CmdBar_ComboBoxItemInsert(
string sBarName,
string sComboBoxParameter,
string sTextToAdd,
int iPositionToInsert)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxItemInsert");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

// Insert item at the specified position
objComboBox.AddItem(sTextToAdd, iPositionToInsert);
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxItemInsert",
msCLASSNAME,
"insert the item '" + sTextToAdd + "' " + gsCRLF +
"into position '" + iPositionToInsert + "'" + gsCRLF +
"of the combo box with" + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxItemRemove

public void CmdBar_ComboBoxItemRemove(
string sBarName,
string sComboBoxParameter,
string sMatchItem)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxItemRemove");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

// Loop through items (1-based indexing)
for (int i = 1; i <= objComboBox.ListCount; i++)
{
if (objComboBox.List[i] == sMatchItem)
{
objComboBox.RemoveItem(i);
break;
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxItemRemove",
msCLASSNAME,
"remove the item '" + sMatchItem + "'" + gsCRLF +
"from the combo box with" + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxReturn

public Office.CommandBarComboBox CmdBar_ComboBoxReturn(
string sBarName,
string sComboBoxParameter)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxReturn");
return null;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

return objComboBox;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxReturn",
msCLASSNAME,
"return the combo box with" + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return null;
}

CmdBar_ComboBoxSelectionChange

public void CmdBar_ComboBoxSelectionChange(
string sBarName,
string sComboBoxParameter,
string sMatchItem,
bool bInformUser = true,
int iComboBoxCtrlNo = 0)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxSelectionChange");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

bool foundMatch = false;

// Search for matching item (1-based indexing)
for (int i = 1; i <= objComboBox.ListCount; i++)
{
if (objComboBox.List[i] == sMatchItem)
{
foundMatch = true;
objComboBox.ListIndex = i;
return;
}
}

// If not found, optionally inform user
if (!foundMatch && bInformUser)
{
System.Windows.Forms.MessageBox.Show(
"The item '" + sMatchItem + "' is not in the combo box with" +
" the parameter '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar '" + sBarName + "'.",
gobjSolution.SolutionFormPrefix + "ComboboxSelectionChange [clsCmdBar]",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation
);
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxSelectionChange",
msCLASSNAME,
"change the selection in the combo box with" + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"to the value '" + sMatchItem + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxSelectionExists

public bool CmdBar_ComboBoxSelectionExists(
string sBarName,
string sComboBoxParameter,
string sMatchItem)
{
Office.CommandBarComboBox objComboBox = null;
bool result = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxSelectionExists");
return false;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return false;

// Search for matching item (1-based indexing)
for (int i = 1; i <= objComboBox.ListCount; i++)
{
if (objComboBox.List[i] == sMatchItem)
{
result = true;
return true;
}
}

result = false;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxSelectionExists",
msCLASSNAME,
"determine if the text '" + sMatchItem + "'" + gsCRLF +
"exists in the combo box " + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return result;
}

CmdBar_ComboBoxSelectionGet

public string CmdBar_ComboBoxSelectionGet(
string sBarName,
string sComboBoxParameter)
{
Office.CommandBarComboBox objComboBox = null;
string result = "";

try
{
if (gbEND_GENERAL)
return "";

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxSelectionGet");
return "";
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return "";

result = objComboBox.Text;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxSelectionGet",
msCLASSNAME,
"return the selection that has been made in the combo box with" + gsCRLF +
"Parameter '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return result;
}

CmdBar_ComboBoxToComboBox

public void CmdBar_ComboBoxToComboBox(
string sBarName,
int iComboBoxID,
string sComboBoxFromParameter,
string sComboBoxFromTag,
System.Windows.Forms.ComboBox cboComboBox)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxToComboBox");
return;
}

// Locate the CommandBarComboBox by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxFromParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

// Copy items (1-based indexing)
for (int i = 1; i <= objComboBox.ListCount; i++)
{
cboComboBox.Items.Add(objComboBox.List[i]);
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxToComboBox",
msCLASSNAME,
"add all the items from the combo box with" + gsCRLF +
"Parameter: '" + sComboBoxFromParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'." + gsCRLF +
"and add them to the combobox '" + cboComboBox.Name + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxToListBox

public void CmdBar_ComboBoxToListBox(
string sBarName,
string sComboBoxParameter,
System.Windows.Forms.ListBox lsbListBox)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxToListBox");
return;
}

// Locate the CommandBarComboBox by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

// Copy items (1-based indexing)
for (int i = 1; i <= objComboBox.ListCount; i++)
{
lsbListBox.Items.Add(objComboBox.List[i]);
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxToListBox",
msCLASSNAME,
"add all the items from the combo box with" + gsCRLF +
"Parameter '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'." + gsCRLF +
"and add them to the listbox '" + lsbListBox.Name + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ComboBoxWidthChange

public void CmdBar_ComboBoxWidthChange(
string sBarName,
string sComboBoxParameter,
int iComboBoxWidth)
{
Office.CommandBarComboBox objComboBox = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxWidthChange");
return;
}

// Locate the combo box by Parameter
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sComboBoxParameter)
{
objComboBox = (Office.CommandBarComboBox)bar.Controls[i];
break;
}
}

if (objComboBox == null)
return;

objComboBox.Width = iComboBoxWidth;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objComboBox = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ComboBoxWidthChange",
msCLASSNAME,
"change the width of the combobox with" + gsCRLF +
"Parameter: '" + sComboBoxParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ControlAddButton

public Office.CommandBarButton CmdBar_ControlAddButton(
string sBarName,
int iControlID,
string sControlCaption,
bool bBeginGroup = false,
int iButtonFaceID = 1,
bool bPasteFace = false,
bool bEnable = true,
bool bTemporary = false,
bool bResetClipboard = false)
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ControlAdd");
return null;
}

objButton = (Office.CommandBarButton)mCommandBars[sBarName].Controls.Add(
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Id: iControlID
);

objButton.Caption = sControlCaption;
objButton.BeginGroup = bBeginGroup;

if (!bPasteFace && iButtonFaceID > 0)
{
objButton.FaceId = iButtonFaceID;
}
else if (bPasteFace)
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false
);
}
}

objButton.Enabled = bEnable;

return objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlAddButton",
msCLASSNAME,
"add the control with" + gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}

return null;
}

CmdBar_ControlAddTest

public bool CmdBar_ControlAddTest(
Office.CommandBarPopup objControlPopup,
int iControlID)
{
Office.CommandBarControl objControl = null;
bool result = false;

try
{
if (gbEND_GENERAL)
return false;

result = true;

// Try to add the control
objControl = objControlPopup.Controls.Add(Id: iControlID);

// If successful, delete it immediately
objControl.Delete();
}
catch (System.Runtime.InteropServices.COMException)
{
result = false;
}
catch (Exception)
{
result = false;
}
finally
{
objControl = null;

if (!result)
{
clszMessagesGeneral.ToolbarBuiltInControlDoesNotExistWarning(
iControlID,
""
);
}
}

return result;
}

CmdBar_ControlEnabledChange

public void CmdBar_ControlEnabledChange(
string sBarName,
int iControlID,
string sControlCaption,
bool bEnable,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ControlEnabledChange");
return;
}

// 1) Lookup by Caption
if (sControlCaption.Length > 0)
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sControlCaption)
{
objControl = ctrl;
break;
}
}
}
else
{
// 2) Lookup by ID
objControl = mCommandBars[sBarName].FindControl(Id: iControlID);
}

// Not found ? warn
if (objControl == null)
{
if (bInformUser)
{
clszMessagesGeneral.ToolbarControlDoesNotExistWarning(
sBarName,
iControlID,
sControlCaption
);
}
}
else
{
// Found ? enable/disable
objControl.Enabled = bEnable;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlEnabledChange",
msCLASSNAME,
"enable or disable the control with" + gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ControlEnabledGet

public bool CmdBar_ControlEnabledGet(
string sBarName,
int iControlID,
string sControlCaption,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
bool result = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("ControlEnabledGet");
return false;
}

// 1) Lookup by Caption
if (sControlCaption.Length > 0)
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sControlCaption)
{
objControl = ctrl;
break;
}
}
}
else
{
// 2) Lookup by ID
objControl = mCommandBars[sBarName].FindControl(Id: iControlID);
}

// Not found ? warn and exit
if (objControl == null)
{
if (bInformUser)
{
clszMessagesGeneral.ToolbarControlDoesNotExistWarning(
sBarName,
iControlID,
sControlCaption
);
}
return false;
}

// Found ? return Enabled state
result = objControl.Enabled;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlEnabledGet",
msCLASSNAME,
"determine whether the control with" + gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
"is enabled or disabled" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return result;
}

CmdBar_ControlExecute

public void CmdBar_ControlExecute(
string sBarName,
int iControlID,
string sControlCaption = "")
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ControlExecute");
return;
}

// Locate the button by ID
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Id == iControlID)
{
objButton = (Office.CommandBarButton)bar.Controls[i];
break;
}
}

// Execute the button (VBA assumes objButton is not Nothing)
objButton?.Execute();
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlExecute",
msCLASSNAME,
"execute the control with" + gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ControlIDReturn

public int CmdBar_ControlIDReturn(
string sBarName,
int iControlPositionNo)
{
int result = 0;

try
{
if (gbEND_GENERAL)
return 0;

if (mCommandBars == null)
{
CommandBarsIsNothing("ControlIDReturn");
return 0;
}

result = mCommandBars[sBarName].Controls[iControlPositionNo].Id;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlIDReturn",
msCLASSNAME,
"return the ID for" + gsCRLF +
"control number '" + iControlPositionNo + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return result;
}

CmdBar_ControlInsert

public void CmdBar_ControlInsert(
string sBarName,
int iBeforeControlID,
string sBeforeControlCaption,
string sBeforeControlParameter,
int iControlID,
string sControlCaption = "",
int iButtonFaceID = -1,
bool bBeginGroup = false,
bool bTemporary = false)
{
Office.CommandBarControl objControl = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ControlInsert");
return;
}

int iBeforeControlNo = mCommandBars[sBarName].Controls.Count + 1;

// Find insertion point
var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
var ctrl = bar.Controls[i];

if (iBeforeControlID > 0 && ctrl.Id == iBeforeControlID)
{
iBeforeControlNo = i;
break;
}

if (sBeforeControlCaption.Length > 0 &&
ctrl.Caption == sBeforeControlCaption)
{
iBeforeControlNo = i;
break;
}

if (sBeforeControlParameter.Length > 0 &&
ctrl.Parameter == sBeforeControlParameter)
{
iBeforeControlNo = i;
break;
}
}

// Insert the new control
objControl = bar.Controls.Add(
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Id: iControlID,
Before: iBeforeControlNo
);

objControl.BeginGroup = bBeginGroup;

// If it's a button, configure face + caption
if (iButtonFaceID > -1)
{
objButton = (Office.CommandBarButton)objControl;
objButton.FaceId = iButtonFaceID;

if (sControlCaption.Length > 0)
objButton.Caption = sControlCaption;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlInsert",
msCLASSNAME,
"insert the control with" + gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"before the control with" + gsCRLF +
"ID: '" + iBeforeControlID + "'" + gsCRLF +
"Caption: '" + sBeforeControlCaption + "'" + gsCRLF +
"Parameter: '" + sBeforeControlParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ControlInsertButton

public void CmdBar_ControlInsertButton(
string sBarName,
int iControlID,
int iBeforeControlID = 0,
string sBeforeControlCaption = "",
int iControlFaceID = 0,
bool bPasteFace = false,
bool bBeginGroup = false,
bool bTemporary = false,
bool bResetClipboard = true)
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ControlInsertButton");
return;
}

int iBeforeControl = 0;
var bar = mCommandBars[sBarName];

// 1) Lookup by Caption
if (sBeforeControlCaption.Length > 0)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Caption == sBeforeControlCaption)
{
iBeforeControl = i;
break;
}
}
}

// 2) Lookup by ID
if (iBeforeControlID > 0)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Id == iBeforeControlID)
{
iBeforeControl = i;
break;
}
}
}

// 3) Insert the button
if (sBeforeControlCaption.Length > 0 || iBeforeControlID > 0)
{
objButton = (Office.CommandBarButton)bar.Controls.Add(
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Id: iControlID,
Before: iBeforeControl
);
}
else
{
objButton = (Office.CommandBarButton)bar.Controls.Add(
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Id: iControlID
);
}

// 4) Configure button
objButton.BeginGroup = bBeginGroup;

if (!bPasteFace && iControlFaceID > 0)
{
objButton.FaceId = iControlFaceID;
}
else if (bPasteFace)
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false
);
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlInsertButton",
msCLASSNAME,
"insert the control with" + gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"before the control with" + gsCRLF +
"ID: '" + iBeforeControlID + "'" + gsCRLF +
"Caption: '" + sBeforeControlCaption + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ControlReturn

public Office.CommandBarButton CmdBar_ControlReturn(
string sBarName,
string sControlTag,
string sControlParameter,
int iControlID = -1,
string sControlCaption = "",
bool bInformUser = false)
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
zCommandBarsIsNothing("ButtonReturn");
return null;
}

objButton = mCmdBarFind.FindButton(
sBarName,
sControlTag,
sControlParameter,
iControlID,
sControlCaption,
bInformUser
);

return objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (System.Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlReturn",
msCLASSNAME,
"return the button with" + gsCRLF +
gsCRLF +
"Tag: '" + sControlTag + "'" + gsCRLF +
"Parameter: '" + sControlParameter + "'" + gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}

return null;
}

CmdBar_ControlsDelete

public void CmdBar_ControlsDelete(
string sBarName)
{
try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ControlsDelete");
return;
}

// Delete all controls by repeatedly deleting index 1
Office.CommandBar bar = mCommandBars[sBarName];
int controlCount = bar.Controls.Count;

for (int i = 1; i <= controlCount; i++)
{
bar.Controls[1].Delete();
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlsDelete",
msCLASSNAME,
"delete all the controls " +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ControlVisibleChange

public void CmdBar_ControlVisibleChange(
string sBarName,
int iControlID,
string sControlCaption,
bool bVisible,
bool bShortcutMenu = false,
bool bInformUser = false)
{
Office.CommandBarControl objControl = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
zCommandBarsIsNothing("ButtonReturn");
return;
}

// NORMAL COMMAND BARS
if (!bShortcutMenu)
{
objControl = mCmdBarFind.FindControl(
sBarName,
iControlID,
sControlCaption
);

if (objControl != null)
objControl.Visible = bVisible;

return;
}

// SHORTCUT MENUS — cannot use FindControl
var bar = mCommandBars[sBarName];

if (iControlID > -1)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Id == iControlID)
{
bar.Controls[i].Visible = bVisible;
}
}
}

// NOTE: VBA has an empty block for caption matching.
// We preserve that behaviour exactly.
if (sControlCaption.Length > 0)
{
// intentionally empty — behaviour preserved
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (System.Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlVisibleChange",
msCLASSNAME,
"display or hide the control with" + gsCRLF +
gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_ControlVisibleGet

public bool CmdBar_ControlVisibleGet(
string sBarName,
int iControlID,
string sControlCaption,
bool bShortcutMenu = false,
bool bInformUser = false)
{
Office.CommandBarControl objControl = null;
bool result = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
zCommandBarsIsNothing("ControlVisibleGet");
return false;
}

// NORMAL COMMAND BARS
if (!bShortcutMenu)
{
objControl = mCmdBarFind.FindControl(
sBarName,
iControlID,
sControlCaption
);

result = objControl.Visible;
return result;
}

// SHORTCUT MENUS — cannot use FindControl
var bar = mCommandBars[sBarName];

if (iControlID > -1)
{
for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Id == iControlID)
{
if (bar.Controls[i].Visible)
{
result = true;
return true;
}
}
}
}

// VBA has an empty caption block — preserve behaviour
if (sControlCaption.Length > 0)
{
// intentionally empty
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (System.Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ControlVisibleGet",
msCLASSNAME,
"determine whether the control with" + gsCRLF +
gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
"is visible or not" + gsCRLF +
gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return result;
}

CmdBar_DropDownAdd

Adds a drop-down menu to a command bar.
public Office.CommandBarPopup CmdBar_DropDownAdd(
string sBarName,
Office.CommandBars objCommandBars,
string sDropDownTag = "",
string sDropDownParameter = "",
int iDropDownID = -1,
string sDropDownCaption = "",
bool bBeginGroup = false,
bool bInformUser = true)
{
Office.CommandBarPopup objPopup = null;

try
{
// Early exit if an error has already occurred
if (Properties.Settings.Default.ERROR_OCCURRED)
return null;

// Create popup
objPopup = (Office.CommandBarPopup)objCommandBars.Add(
Office.MsoControlType.msoControlPopup,
Temporary: true
);

// Assign properties
objPopup.Parameter = sDropDownParameter;
objPopup.Tag = sDropDownTag;
objPopup.Caption = sDropDownCaption;
objPopup.BeginGroup = bBeginGroup;

return objPopup;
}
catch (Exception ex)
{
modMessages.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex,
"add this drop-down to the '" + sBarName + "' command bar:" +
Environment.NewLine + Environment.NewLine +
"Tag '" + sDropDownTag + "'" + Environment.NewLine +
"Parameter '" + sDropDownParameter + "'" + Environment.NewLine +
"ID '" + iDropDownID + "'" + Environment.NewLine +
"Caption '" + sDropDownCaption + "'"
);

return null;
}
}

CmdBar_DropDownButtonCaptionChange

public void CmdBar_DropDownButtonCaptionChange(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sButtonParameter,
string sButtonCaption,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownButtonCaptionSet");
return;
}

// Locate the dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownButtonCaptionChange",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Find the button by parameter
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}

// Update caption
if (objButton != null)
{
objButton.Caption = sButtonCaption;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownButtonCaptionChange",
msCLASSNAME,
"change the caption to '" + sButtonCaption + "' for the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"on the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownButtonDelete

public void CmdBar_DropDownButtonDelete(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sButtonParameter,
string sButtonCaption = "",
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownButtonEnabledChange");
return;
}

// Locate the dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownButtonDelete",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Find button by Parameter
if (sButtonCaption.Length == 0)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}
}

// Find button by Caption
if (sButtonParameter.Length == 0)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Caption == sButtonCaption)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}
}

// Delete the button
objButton?.Delete();
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ButtonDelete",
msCLASSNAME,
"delete the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownButtonEnabledChange

public void CmdBar_DropDownButtonEnabledChange(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sButtonParameter,
string sButtonCaption,
bool bEnable,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownButtonEnabledChange");
return;
}

// Locate the dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownButtonEnabledChange",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Find button by Parameter
if (sButtonCaption.Length == 0)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}
}

// Find button by Caption
if (sButtonParameter.Length == 0)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Caption == sButtonCaption)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}
}

// Enable/disable the button
if (objButton != null)
{
objButton.Enabled = bEnable;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownButtonEnabledChange",
msCLASSNAME,
"enable or disable the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"on the drop-down menu with" + gsCRLF +
"Tag '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownButtonEnabledGet

public bool CmdBar_DropDownButtonEnabledGet(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sButtonParameter,
string sButtonCaption)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

bool result = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownButtonEnabledGet");
return false;
}

// Locate the dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownButtonEnabledGet",
sBarName,
sDropDownTag,
sDropDownCaption
);
return false;
}

// Find button by Parameter
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}

if (objButton != null)
result = objButton.Enabled;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownButtonEnabledGet",
msCLASSNAME,
"determine if the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"on the drop-down menu with" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"is enabled or disabled" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}

return result;
}

CmdBar_DropDownButtonFaceCopy

public void CmdBar_DropDownButtonFaceCopy(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
int iButtonID,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownButtonFaceCopy");
return;
}

// Locate the dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownButtonFaceCopy",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Find button by ID
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Id == iButtonID)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}

// Preserve clipboard and copy face
mClipboardObject = System.Windows.Forms.Clipboard.GetDataObject();
objButton?.CopyFace();
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownButtonFaceCopy",
msCLASSNAME,
"copy the face with" + gsCRLF +
"ID: '" + iButtonID + "'" + gsCRLF +
"on the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "'" + gsCRLF +
"from the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownButtonInsert

public Office.CommandBarButton CmdBar_DropDownButtonInsert(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
int iBeforeButtonID,
string sBeforeButtonCaption,
string sBeforeButtonParameter,
string sButtonCaption,
string sButtonParameter,
string sButtonTag,
string sButtonOnAction,
bool bBeginGroup = false,
int iButtonFaceID = 1,
bool bPasteFace = false,
string sButtonState = "UP",
bool bTemporary = false,
bool bInformUser = true,
bool bResetClipboard = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownButtonInsert");
return null;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownButtonInsert",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return null;
}

// Determine insertion index
int iBeforeControlNo = objDropdownPopup.Controls.Count + 1;

for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
var ctrl = objDropdownPopup.Controls[i];

if (iBeforeButtonID > 0 && ctrl.Id == iBeforeButtonID)
{
iBeforeControlNo = i;
break;
}

if (sBeforeButtonCaption.Length > 0 && ctrl.Caption == sBeforeButtonCaption)
{
iBeforeControlNo = i;
break;
}

if (sBeforeButtonParameter.Length > 0 && ctrl.Parameter == sBeforeButtonParameter)
{
iBeforeControlNo = i;
break;
}
}

// Insert the button
objButton = (Office.CommandBarButton)objDropdownPopup.Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Before: iBeforeControlNo,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sButtonParameter
);

// Configure button
objButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
objButton.Tag = sButtonTag;
objButton.OnAction = sButtonOnAction;
objButton.Caption = sButtonCaption;
objButton.BeginGroup = bBeginGroup;

if (!bPasteFace)
{
objButton.FaceId = iButtonFaceID;
}
else
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false
);
}
}

if (sButtonState == "DOWN")
{
objButton.State = Office.MsoButtonState.msoButtonDown;
}

return objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownButtonInsert",
msCLASSNAME,
"insert the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"to the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}

return null;
}

CmdBar_DropDownButtonReturn

public Office.CommandBarButton CmdBar_DropDownButtonInsert(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
int iBeforeButtonID,
string sBeforeButtonCaption,
string sBeforeButtonParameter,
string sButtonCaption,
string sButtonParameter,
string sButtonTag,
string sButtonOnAction,
bool bBeginGroup = false,
int iButtonFaceID = 1,
bool bPasteFace = false,
string sButtonState = "UP",
bool bTemporary = false,
bool bInformUser = true,
bool bResetClipboard = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownButtonInsert");
return null;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownButtonInsert",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return null;
}

// Determine insertion index
int iBeforeControlNo = objDropdownPopup.Controls.Count + 1;

for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
var ctrl = objDropdownPopup.Controls[i];

if (iBeforeButtonID > 0 && ctrl.Id == iBeforeButtonID)
{
iBeforeControlNo = i;
break;
}

if (sBeforeButtonCaption.Length > 0 && ctrl.Caption == sBeforeButtonCaption)
{
iBeforeControlNo = i;
break;
}

if (sBeforeButtonParameter.Length > 0 && ctrl.Parameter == sBeforeButtonParameter)
{
iBeforeControlNo = i;
break;
}
}

// Insert the button
objButton = (Office.CommandBarButton)objDropdownPopup.Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Before: iBeforeControlNo,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Parameter: sButtonParameter
);

// Configure button
objButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
objButton.Tag = sButtonTag;
objButton.OnAction = sButtonOnAction;
objButton.Caption = sButtonCaption;
objButton.BeginGroup = bBeginGroup;

if (!bPasteFace)
{
objButton.FaceId = iButtonFaceID;
}
else
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false
);
}
}

if (sButtonState == "DOWN")
{
objButton.State = Office.MsoButtonState.msoButtonDown;
}

return objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownButtonInsert",
msCLASSNAME,
"insert the button with" + gsCRLF +
"Parameter: '" + sButtonParameter + "'" + gsCRLF +
"to the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}

return null;
}

CmdBar_DropDownButtonUpDown

public void CmdBar_DropDownButtonUpDown(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sButtonParameter,
string sButtonCaption,
bool bButtonUp,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownButtonUpDown");
return;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownButtonUpDown",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Find button by Parameter
if (sButtonParameter.Length > 0)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Parameter == sButtonParameter)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}
}

// Find button by Caption
if (objButton == null && sButtonCaption.Length > 0)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Caption == sButtonCaption)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}
}

// Apply state
if (objButton != null)
{
objButton.State = bButtonUp
? Office.MsoButtonState.msoButtonUp
: Office.MsoButtonState.msoButtonDown;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownButtonUpDown",
msCLASSNAME,
"change the button state to '" + bButtonUp + "' for the button with" + gsCRLF +
"Caption: '" + sButtonCaption + "'" + gsCRLF +
"to the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownCheckBoxCaptionChange

public void CmdBar_DropDownCheckBoxCaptionChange(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sCheckBoxParameter,
string sCheckBoxCaption,
int iCheckBoxID,
string sNewCheckBoxParameter,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownCheckBoxCaptionChange");
return;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownCheckBoxCaptionChange",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Find checkbox by Parameter, Caption, or ID
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
var ctrl = objDropdownPopup.Controls[i];

if (sCheckBoxParameter.Length > 0 &&
ctrl.Parameter == sCheckBoxParameter)
{
objButton = (Office.CommandBarButton)ctrl;
break;
}

if (sCheckBoxCaption.Length > 0 &&
ctrl.Caption == sCheckBoxCaption)
{
objButton = (Office.CommandBarButton)ctrl;
break;
}

if (iCheckBoxID > -1 &&
ctrl.Id == iCheckBoxID)
{
objButton = (Office.CommandBarButton)ctrl;
break;
}
}

// Update caption
if (objButton != null)
{
objButton.Caption = sNewCheckBoxParameter;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownCheckBoxCaptionChange",
msCLASSNAME,
"change the caption of the checkbox with" + gsCRLF +
"Parameter: '" + sCheckBoxParameter + "'" + gsCRLF +
"on the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "'" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownCheckBoxCaptionGet

public string CmdBar_DropDownCheckBoxCaptionGet(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sCheckBoxParameter,
int iCheckBoxID,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

string result = "";

try
{
if (gbEND_GENERAL)
return "";

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownCheckBoxCaptionGet");
return "";
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownCheckBoxCaptionGet",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return "";
}

// Find checkbox by Parameter
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Parameter == sCheckBoxParameter)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
break;
}
}

if (objButton != null)
result = objButton.Caption;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownCheckBoxCaptionGet",
msCLASSNAME,
"return the caption for the checkbox with" + gsCRLF +
"Parameter: '" + sCheckBoxParameter + "'" + gsCRLF +
"ID: '" + iCheckBoxID + "'" + gsCRLF +
"to the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"and tag '" + sDropDownTag + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return result;
}

CmdBar_DropDownCheckBoxEnabledChange

public void CmdBar_DropDownCheckBoxEnabledChange(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sCheckBoxParameter,
string sCheckBoxCaption,
int iCheckBoxID,
bool bEnable,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownCheckBoxEnabledChange");
return;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownCheckBoxEnabledChange",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Find checkbox by Parameter
foreach (Office.CommandBarControl ctrl in objDropdownPopup.Controls)
{
if (ctrl.Parameter == sCheckBoxParameter)
{
objButton = (Office.CommandBarButton)ctrl;
break;
}
}

// Apply enabled/disabled state
if (objButton != null)
{
objButton.Enabled = bEnable;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownCheckBoxEnabledChange",
msCLASSNAME,
"enable or diable the checkbox with" + gsCRLF +
"Parameter: '" + sCheckBoxParameter + "'" + gsCRLF +
"on the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "'" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownCheckBoxValue

public bool CmdBar_DropDownCheckBoxValue(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sCheckBoxParameter,
string sCheckBoxCaption = "",
int iCheckBoxID = -1,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

bool result = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownCheckBoxValue");
return false;
}

// ToolbarExists check
if (!ToolbarExists(sBarName, null, true))
return false;

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownCheckBoxValue",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return false;
}

// Find checkbox by Parameter
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Parameter == sCheckBoxParameter)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls[i];
}
}

if (objButton != null)
{
if (objButton.State == Office.MsoButtonState.msoButtonUp)
result = false;

if (objButton.State == Office.MsoButtonState.msoButtonDown)
result = true;
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownCheckBoxValue",
msCLASSNAME,
"return the status of the checkbox with" + gsCRLF +
"Parameter: '" + sCheckBoxParameter + "'" + gsCRLF +
"to the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}

return result;
}

CmdBar_DropDownControlAdd

public void CmdBar_DropDownControlAdd(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
int iControlID,
string sControlCaption,
bool bBeginGroup = false,
int iControlFaceID = 1,
bool bPasteFace = false,
bool bEnable = true,
bool bTemporary = false,
bool bInformUser = true,
bool bResetClipboard = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownControlAdd");
return;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownControlAdd",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Add control by ID
objButton = (Office.CommandBarButton)objDropdownPopup.Controls.Add(
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Id: iControlID
);

// Configure control
objButton.Caption = sControlCaption;
objButton.BeginGroup = bBeginGroup;

if (!bPasteFace && iControlFaceID > 0)
{
objButton.FaceId = iControlFaceID;
}
else if (bPasteFace)
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false
);
}
}

objButton.Enabled = bEnable;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownControlAdd",
msCLASSNAME,
"add the control with" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
"Face ID '" + iControlFaceID + "'" + gsCRLF +
"to the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownControlDelete

public void CmdBar_DropDownControlDelete(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sControlParameter = "",
string sControlCaption = "",
int iControlID = -1,
string sControlTag = "",
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarControl objControl2 = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownControlDelete");
return;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
break;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownControlDelete",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// 1) Match by Parameter
if (sControlParameter.Length > 0)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Parameter == sControlParameter)
{
objControl2 = objDropdownPopup.Controls[i];
break;
}
}
}

// 2) Match by Caption
if (objControl2 == null && sControlCaption.Length > 0)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Caption == sControlCaption)
{
objControl2 = objDropdownPopup.Controls[i];
break;
}
}
}

// 3) Match by ID
if (objControl2 == null && iControlID > -1)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Id == iControlID)
{
objControl2 = objDropdownPopup.Controls[i];
break;
}
}
}

// 4) Match by Tag
if (objControl2 == null && sControlTag.Length > 0)
{
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Tag == sControlTag)
{
objControl2 = objDropdownPopup.Controls[i];
break;
}
}
}

// Delete if found
objControl2?.Delete();
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objDropdownPopup = null;
objControl = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownControlDelete",
msCLASSNAME,
"delete the control with " + gsCRLF +
"Paramater: '" + sControlParameter + "'" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"Tag: '" + sControlTag + "'" + gsCRLF +
"on the drop-down menu with " + gsCRLF +
"Caption: '" + sDropDownCaption + "'" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownControlEnabledChange

public void CmdBar_DropDownControlEnabledChange(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
int iControlID,
string sControlCaption,
bool bEnable,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarControl objControl2 = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownControlEnabledChange");
return;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownControlEnabledChange",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// 1) Match by ID
if (iControlID > 0)
{
foreach (Office.CommandBarControl ctrl in objDropdownPopup.Controls)
{
if (ctrl.Id == iControlID)
{
objControl2 = ctrl;
break;
}
}
}

// 2) Match by Caption
if (objControl2 == null && sControlCaption.Length > 0)
{
foreach (Office.CommandBarControl ctrl in objDropdownPopup.Controls)
{
if (ctrl.Caption == sControlCaption)
{
objControl2 = ctrl;
break;
}
}
}

// If still not found ? warn and exit
if (objControl2 == null)
{
if (bInformUser)
{
clszMessagesGeneral.ToolbarControlDoesNotExistWarning(
sBarName,
iControlID,
sControlCaption
);
}
return;
}

// Apply enabled/disabled state
objControl2.Enabled = bEnable;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownControlEnabledChange",
msCLASSNAME,
"enable or disable the control with" + gsCRLF +
"ID: '" + iControlID + "' " + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
"to the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownControlExecute

public void CmdBar_DropDownControlExecute(
string sBarName,
int iControlID = -1,
string sDropDownTag = "",
string sDropDownCaption = "",
string sControlCaption = "",
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarControl objControl2 = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownControlExecute");
return;
}

// 1) Direct execution by ID
if (iControlID > -1)
{
objControl2 = mCommandBars.FindControl(Id: iControlID);
objControl2?.Execute();
return;
}

// 2) Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownControlExecute",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// 3) Find control by Caption
for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
if (objDropdownPopup.Controls[i].Caption == sControlCaption)
{
objControl2 = objDropdownPopup.Controls[i];
break;
}
}

// Execute if found
objControl2?.Execute();
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
if (bInformUser)
{
clsError.Handle(
"DropDownControlExecute",
msCLASSNAME,
"execute the button with" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
"to the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
" on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}
}

CmdBar_DropDownControlInsert

public void CmdBar_DropDownControlInsert(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
int iBeforeControlID,
string sBeforeControlCaption,
string sBeforeControlParameter,
int iControlID,
string sControlCaption,
int iControlFaceID = 0,
bool bEnable = true,
bool bBeginGroup = false,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownControlInsert");
return;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownControlInsert",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Determine insertion index
int iBeforeControlNo = objDropdownPopup.Controls.Count + 1;

for (int i = 1; i <= objDropdownPopup.Controls.Count; i++)
{
var ctrl = objDropdownPopup.Controls[i];

if (iBeforeControlID > 0 && ctrl.Id == iBeforeControlID)
{
iBeforeControlNo = i;
break;
}

if (sBeforeControlCaption.Length > 0 &&
ctrl.Caption == sBeforeControlCaption)
{
iBeforeControlNo = i;
break;
}

if (sBeforeControlParameter.Length > 0 &&
ctrl.Parameter == sBeforeControlParameter)
{
iBeforeControlNo = i;
break;
}
}

// Insert control
if (iControlID == -1)
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Before: iBeforeControlNo
);
}
else
{
objButton = (Office.CommandBarButton)objDropdownPopup.Controls.Add(
Id: iControlID,
Before: iBeforeControlNo
);
}

// Configure control
objButton.Caption = sControlCaption;
objButton.BeginGroup = bBeginGroup;
objButton.Enabled = bEnable;

if (iControlFaceID > 0)
objButton.FaceId = iControlFaceID;

objButton.Enabled = bEnable;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownControlInsert",
msCLASSNAME,
"insert the control with" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
"Face ID: '" + iControlFaceID + "'" + gsCRLF +
"before the control with" + gsCRLF +
"Caption: '" + sBeforeControlCaption + "'" + gsCRLF +
"to the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "'" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownDelete

public void CmdBar_DropDownDelete(
string sBarName,
string sDropDownTag = "",
string sDropDownCaption = "",
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownDelete");
return;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownDelete",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Delete the dropdown
objDropdownPopup.Delete();
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownDelete",
msCLASSNAME,
"delete the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "' " + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"from the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownEnabled

public void CmdBar_DropDownEnabled(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
bool bEnable,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownEnabled");
return;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If popup not found
if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownEnabled",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Enable/disable the dropdown
objDropdownPopup.Enabled = bEnable;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"CmdBar_DropDownEnabled",
msCLASSNAME,
"enable or disable the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "'" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownExists

public bool CmdBar_DropDownExists(
string sBarName,
string sDropDownTag,
string sDropDownCaption = "",
bool bInformUser = false)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;

bool result = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownExists");
return false;
}

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// Set return value
result = (objDropdownPopup != null);
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownExists",
msCLASSNAME,
"determine if the drop-down menu with" + gsCRLF +
"Caption: '" + sDropDownCaption + "'" + gsCRLF +
"Tag '" + sDropDownTag + "'" + gsCRLF +
"exists'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return result;
}

CmdBar_DropDownExtendControlAdd

public void CmdBar_DropDownExtendControlAdd(
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sExtensionTag,
string sExtensionCaption,
int iControlID,
string sControlCaption,
bool bBeginGroup = false,
int iControlFaceID = 1,
bool bPasteFace = false,
bool bEnable = true,
bool bTemporary = false,
bool bInformUser = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarPopup objExtendPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownExtendControlAdd");
return;
}

// 1) EXTENSION FOUND DIRECTLY BY TAG (recursive)
if (sExtensionTag.Length > 0)
{
objExtendPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sExtensionTag, Recursive: true);
}
else
{
// 2) EXTENSION FOUND INSIDE A DROPDOWN

// Locate dropdown popup
if (sDropDownTag.Length > 0)
{
objDropdownPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sDropDownTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sDropDownCaption)
{
objDropdownPopup = (Office.CommandBarPopup)ctrl;
}
}
}

if (objDropdownPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuDropDownDoesNotExistWarning(
"DropDownExtendControlAdd",
sBarName,
sDropDownTag,
sDropDownCaption
);
}
return;
}

// Find extension popup by Caption
foreach (Office.CommandBarControl ctrl in objDropdownPopup.Controls)
{
if (ctrl.Caption == sExtensionCaption)
{
objExtendPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// If extension popup still not found
if (objExtendPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.MenuExtensionDoesNotExistWarning(
"DropDownExtendControlAdd",
sBarName,
sDropDownTag,
sDropDownCaption,
sExtensionTag,
sExtensionCaption
);
}
return;
}

// Validate via ControlAddTest
if (!ControlAddTest(objExtendPopup, iControlID))
return;

// Add control
objButton = (Office.CommandBarButton)objExtendPopup.Controls.Add(
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Id: iControlID
);

// Configure control
objButton.Caption = sControlCaption;
objButton.BeginGroup = bBeginGroup;

if (!bPasteFace)
{
objButton.FaceId = iControlFaceID;
}
else
{
objButton.PasteFace();
}

objButton.Enabled = bEnable;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objExtendPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownExtendControlAdd",
msCLASSNAME,
"add the control with" + gsCRLF +
"ID: '" + iControlID + "'" + gsCRLF +
"Caption: '" + sControlCaption + "'" + gsCRLF +
"Face ID: '" + iControlFaceID + "'" + gsCRLF +
"to the extension bar with" + gsCRLF +
"Tag: '" + sExtensionTag + "'" + gsCRLF +
"Caption: '" + sExtensionCaption + "'" + gsCRLF +
"on the drop-down menu with" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"Caption '" + sDropDownCaption + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownExtendControlEnabledChange

public void CmdBar_DropDownExtendControlEnabledChange(
bool bEnable,
string sBarName,
string sDropDownTag,
string sDropDownCaption,
string sExtensionName,
string sControlName,
int iDropDownCtrl = -1,
int iControlNo = -1)
{
try
{
if (gbEND_GENERAL)
return;

// not written yet
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownExtendControlEnabledChange",
msCLASSNAME,
"enable or disable the control with" + gsCRLF +
"Name: '" + sControlName + "'" + gsCRLF +
"from the extension bar with" + gsCRLF +
"Name: '" + sExtensionName + "'" + gsCRLF +
"on the drop-down menu with" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException
);
}
}
}

CmdBar_DropDownInsert

public Office.CommandBarPopup CmdBar_DropDownInsert(
string sBarName,
string sBeforeButtonCaption,
string sDropDownTag,
string sDropDownCaption,
int iDropDownWidth = 50,
bool bBeginGroup = false,
bool bTemporary = false)
{
Office.CommandBar objCommandBar = null;
Office.CommandBarPopup objDropdownPopup = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("DropDownInsert");
return null;
}

objCommandBar = mCommandBars[sBarName];

// Find insertion point
int iBeforeControlNo = objCommandBar.Controls.Count + 1;

for (int i = 1; i <= objCommandBar.Controls.Count; i++)
{
if (objCommandBar.Controls[i].Caption == sBeforeButtonCaption)
{
iBeforeControlNo = i;
break;
}
}

// Find popup bar with same name
for (int i = 1; i <= mCommandBars.Count; i++)
{
var bar = mCommandBars[i];

if (bar.Type == Office.MsoBarType.msoBarTypePopup &&
bar.Name == sBarName)
{
objDropdownPopup = (Office.CommandBarPopup)objCommandBar.Controls.Add(
Type: Office.MsoControlType.msoControlPopup,
Before: iBeforeControlNo,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary)
);
break;
}
}

if (objDropdownPopup == null)
return null;

// Configure popup
objDropdownPopup.Tag = sDropDownTag;
objDropdownPopup.Caption = sDropDownCaption;
objDropdownPopup.Width = iDropDownWidth;
objDropdownPopup.BeginGroup = bBeginGroup;

return objDropdownPopup;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objDropdownPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownInsert",
msCLASSNAME,
"insert the drop-down menu with" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"Caption '" + sDropDownCaption + "'" + gsCRLF +
"to the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return null;
}

CmdBar_DropDownReturn

public Office.CommandBarPopup CmdBar_DropDownReturn(
string sBarName,
string sDropDownTag)
{
Office.CommandBarPopup objDropdownPopup = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ComboBoxReturn");
return null;
}

var bar = mCommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Tag == sDropDownTag)
{
objDropdownPopup = (Office.CommandBarPopup)bar.Controls[i];
break;
}
}

return objDropdownPopup;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"DropDownReturn",
msCLASSNAME,
"return the drop-down menu with" + gsCRLF +
"Tag: '" + sDropDownTag + "'" + gsCRLF +
"from the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException
);
}
}

return null;
}

CmdBar_ExtendAdd

public void CmdBar_ExtendAdd(
string sBarName,
string sExtensionCaption,
string sExtensionTag,
bool bBeginGroup = false,
bool bTemporary = false,
bool bInformUser = true)
{
Office.CommandBarPopup objExtendPopup = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ExtendAdd");
return;
}

objExtendPopup = (Office.CommandBarPopup)mCommandBars[sBarName].Controls.Add(
Type: Office.MsoControlType.msoControlPopup,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary));

// --- Assign properties exactly as in VBA ---
objExtendPopup.Tag = sExtensionTag;
objExtendPopup.Caption = sExtensionCaption;
objExtendPopup.BeginGroup = bBeginGroup;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objExtendPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ExtendAdd",
msCLASSNAME,
"add the extension bar '" + sExtensionCaption + "'" +
gsCRLF + "to the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ExtendButtonAdd

public Office.CommandBarButton CmdBar_ExtendButtonAdd(
string sBarName,
string sExtensionTag,
string sExtensionCaption,
string sButtonCaption,
string sButtonParameter,
string sButtonTag,
string sButtonOnAction,
bool bBeginGroup = false,
int iButtonFaceID = 0,
bool bPasteFace = false,
string sButtonState = "UP",
bool bTemporary = false,
bool bInformUser = true,
bool bResetClipboard = true)
{
Office.CommandBarControl objControl = null;
Office.CommandBarPopup objDropdownPopup = null;
Office.CommandBarPopup objExtendPopup = null;
Office.CommandBarButton objButton = null;
Office.CommandBarButton returnValue = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ExtendButtonAdd");
return null;
}

// --- Locate the extension popup ---
if (sExtensionTag.Length > 0)
{
objExtendPopup = (Office.CommandBarPopup)mCommandBars[sBarName]
.FindControl(Tag: sExtensionTag);
}
else
{
foreach (Office.CommandBarControl ctrl in mCommandBars[sBarName].Controls)
{
if (ctrl.Caption == sExtensionCaption)
{
objExtendPopup = (Office.CommandBarPopup)ctrl;
}
}
}

// --- If extension popup not found ---
if (objExtendPopup == null)
{
if (bInformUser)
{
clszMessagesGeneral.ToolbarExtensionDoesNotExistWarning(
"ExtendButtonAdd",
sBarName,
sExtensionCaption,
sExtensionTag);
}
return null;
}

// --- Add the button to the extension popup ---
objButton = (Office.CommandBarButton)objExtendPopup.Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Parameter: sButtonParameter,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary));

// --- Assign properties exactly as in VBA ---
objButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
objButton.Tag = sButtonTag;
objButton.Caption = sButtonCaption;
objButton.OnAction = sButtonOnAction;
objButton.BeginGroup = bBeginGroup;

if (!bPasteFace)
{
objButton.FaceId = iButtonFaceID;
}
else
{
objButton.PasteFace();

if (bResetClipboard)
{
System.Windows.Forms.Clipboard.SetDataObject(mClipboardObject, false);
mClipboardObject = null;
}
else
{
System.Windows.Forms.Clipboard.SetDataObject(
new System.Windows.Forms.DataObject(), false);
}
}

if (sButtonState == "DOWN")
{
objButton.State = Office.MsoButtonState.msoButtonDown;
}

returnValue = objButton;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objControl = null;
objDropdownPopup = null;
objExtendPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ExtendButtonAdd",
msCLASSNAME,
"add the button called '" + sButtonParameter + "'" + gsCRLF +
"to the extension bar with caption '" + sExtensionCaption + "' " +
"and tag '" + sExtensionTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ExtendControlAdd

public void CmdBar_ExtendControlAdd(
string sBarName,
string sExtensionTag,
string sExtensionCaption,
int iControlID,
string sButtonCaption,
bool bBeginGroup = false,
int iFaceIdNo = 0,
string sButtonToolTip = "",
bool bTemporary = false)
{
Office.CommandBar objCommandBar = null;
Office.CommandBarPopup objExtendPopup = null;
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

objCommandBar = mCommandBars[sBarName];

// --- Locate extension popup by Tag (1-based enumeration) ---
for (int i = 1; i <= objCommandBar.Controls.Count; i++)
{
if (objCommandBar.Controls[i].Tag == sExtensionTag)
{
objExtendPopup = (Office.CommandBarPopup)objCommandBar.Controls[i];
break;
}
}

// If not found, VBA would throw later — we preserve that behaviour.

objButton = (Office.CommandBarButton)objExtendPopup.Controls.Add(
Temporary: clsOfficeCore.TriStateFromBool(bTemporary),
Id: iControlID);

// --- Assign properties exactly as in VBA ---
if (sButtonCaption.Length > 0)
objButton.Caption = sButtonCaption;

if (iFaceIdNo > -1)
objButton.FaceId = iFaceIdNo;

objButton.TooltipText = sButtonToolTip;
objButton.BeginGroup = bBeginGroup;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objCommandBar = null;
objExtendPopup = null;
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ExtendControlAdd",
msCLASSNAME,
"add the control with " +
"the ID '" + iControlID + "'" + gsCRLF +
"on to the extension bar with " +
"the tag '" + sExtensionTag + "'" + gsCRLF +
"on the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ExtendDelete

public Office.CommandBarPopup CmdBar_ExtendDelete(string sBarName, string sExtendTag)
{
// VBA: ExtendDelete = Nothing
Office.CommandBarPopup returnValue = null;

// Delegate to DropDownDelete exactly as VBA does
this.DropDownDelete(sBarName, sExtendTag, "");

return returnValue;
}

CmdBar_ExtendInsert

public Office.CommandBarPopup CmdBar_ExtendInsert(
string sBarName,
string sBeforeButtonCaption,
string sExtensionCaption,
string sExtensionParameter,
string sExtensionTag,
bool bBeginGroup = false,
bool bTemporary = false)
{
return this.DropDownInsert(
sBarName,
sBeforeButtonCaption,
sExtensionTag,
sExtensionCaption,
null, // iDropDownWidth (missing in VBA call)
null, // bBeginGroup (missing in VBA call)
bTemporary);
}

CmdBar_ExtendReturn

public Office.CommandBarPopup CmdBar_ExtendReturn(
string sBarName,
string sExtendTag)
{
return this.DropDownReturn(sBarName, sExtendTag);
}

CmdBar_FindDropDown

public Office.CommandBarPopup CmdBar_FindDropDown(
string sBarName,
string sDropDownTag = "",
string sDropDownParameter = "",
int iDropDownID = 0,
string sDropDownCaption = "")
{
try
{
Office.CommandBar objBar = gApplicationWord.CommandBars[sBarName];

// --- 1. Lookup by Tag ---
if (sDropDownTag.Length > 0)
{
return (Office.CommandBarPopup)gApplicationWord.CommandBars.FindControl(
Type: Office.MsoControlType.msoControlDropdown,
Tag: sDropDownTag);
}

// --- 2. Lookup by Parameter (search within the bar only) ---
if (sDropDownParameter.Length > 0)
{
Office.CommandBar bar = gApplicationWord.CommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Parameter == sDropDownParameter)
{
return (Office.CommandBarPopup)bar.Controls[i];
}
}
}

// --- 3. Lookup by ID ---
if (iDropDownID > -1)
{
return (Office.CommandBarPopup)gApplicationWord.CommandBars.FindControl(
Type: Office.MsoControlType.msoControlDropdown,
Id: iDropDownID);
}

// --- 4. Lookup by Caption (search within the bar only) ---
if (sDropDownCaption.Length > 0)
{
Office.CommandBar bar = gApplicationWord.CommandBars[sBarName];

for (int i = 1; i <= bar.Controls.Count; i++)
{
if (bar.Controls[i].Caption == sDropDownCaption)
{
return (Office.CommandBarPopup)bar.Controls[i];
}
}
}

return null;
}
catch (Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message,
"",
false);

return null;
}
}

CmdBar_FindExtendPopup

public Office.CommandBarPopup CmdBar_FindExtendPopup(
Office.CommandBarPopup objPopUp,
string sExtensionTag,
string sExtensionParameter,
int iExtensionID,
string sExtensionCaption,
bool bInformUser = true)
{
Office.CommandBarPopup returnValue = null;

try
{
if (My.Settings.ERROR_OCCURRED)
return null;

// --- 1. Lookup by Tag ---
if (sExtensionTag.Length > 0)
{
for (int i = 1; i <= objPopUp.Controls.Count; i++)
{
if (objPopUp.Controls[i].Tag == sExtensionTag)
{
returnValue = (Office.CommandBarPopup)objPopUp.Controls[i];
return returnValue;
}
}
}

// --- 2. Lookup by Parameter ---
if (sExtensionParameter.Length > 0)
{
for (int i = 1; i <= objPopUp.Controls.Count; i++)
{
if (objPopUp.Controls[i].Parameter == sExtensionParameter)
{
returnValue = (Office.CommandBarPopup)objPopUp.Controls[i];
return returnValue;
}
}
}

// --- 3. Lookup by ID ---
if (iExtensionID > -1)
{
for (int i = 1; i <= objPopUp.Controls.Count; i++)
{
if (objPopUp.Controls[i].Id == iExtensionID)
{
returnValue = (Office.CommandBarPopup)objPopUp.Controls[i];
return returnValue;
}
}
}

// --- 4. Lookup by Caption ---
if (sExtensionCaption.Length > 0)
{
for (int i = 1; i <= objPopUp.Controls.Count; i++)
{
if (objPopUp.Controls[i].Caption == sExtensionCaption)
{
returnValue = (Office.CommandBarPopup)objPopUp.Controls[i];
return returnValue;
}
}
}
}
catch (Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message,
"",
false);
}

return returnValue;
}

CmdBar_FindPopUp

public Office.CommandBarPopup CmdBar_FindPopUp(
string sBarName,
string sPopUpTag = "",
string sPopUpParameter = "",
int iPopUpID = -1,
string sPopUpCaption = "",
bool bInformUser = true)
{
Office.CommandBarPopup objPopup = null;
Office.CommandBar objBar = null;

try
{
if (My.Settings.ERROR_OCCURRED)
return null;

objBar = gApplicationWord.CommandBars[sBarName];

// --- 1. Lookup by Tag ---
if (sPopUpTag.Length > 0)
{
objPopup = (Office.CommandBarPopup)gApplicationWord.CommandBars.FindControl(
Type: Office.MsoControlType.msoControlPopup,
Tag: sPopUpTag);
}

// --- 2. Lookup by Parameter ---
if (sPopUpParameter.Length > 0)
{
for (int i = 1; i <= objBar.Controls.Count; i++)
{
if (objBar.Controls[i].Parameter == sPopUpParameter)
{
objPopup = (Office.CommandBarPopup)objBar.Controls[i];
break;
}
}
}

// --- 3. Lookup by ID ---
if (iPopUpID > -1)
{
objPopup = (Office.CommandBarPopup)objBar.FindControl(
Type: Office.MsoControlType.msoControlPopup,
Id: iPopUpID);
}

// --- 4. Lookup by Caption ---
if (sPopUpCaption.Length > 0)
{
for (int i = 1; i <= objBar.Controls.Count; i++)
{
if (objBar.Controls[i].Caption == sPopUpCaption)
{
objPopup = (Office.CommandBarPopup)objBar.Controls[i];
break;
}
}
}

// --- Inform user if not found ---
if (objPopup == null && bInformUser)
{
modMessages.CommandBar_ControlDoesNotExist(
System.Reflection.MethodBase.GetCurrentMethod(),
sBarName,
sPopUpTag,
sPopUpParameter,
iPopUpID,
sPopUpCaption,
false,
true);
}

return objPopup;
}
catch (Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message,
"",
false);

return null;
}
finally
{
objBar = null;
}
}

CmdBar_FindPopupControl

public Office.CommandBarControl CmdBar_FindPopupControl(
Office.CommandBarPopup objPopUp,
string sControlTag,
string sControlParameter,
int iControlID,
string sControlCaption,
bool bInformUser = true)
{
Office.CommandBarControl returnValue = null;

try
{
if (My.Settings.ERROR_OCCURRED)
return null;

// --- 1. Lookup by Tag (recursive search on parent bar) ---
if (sControlTag.Length > 0)
{
returnValue = (Office.CommandBarControl)objPopUp.Parent.FindControl(
Tag: sControlTag,
Recursive: true);

if (returnValue != null)
return returnValue;
}

// --- 2. Lookup by Parameter (search only inside this popup) ---
if (sControlParameter.Length > 0)
{
for (int i = 1; i <= objPopUp.Controls.Count; i++)
{
if (objPopUp.Controls[i].Parameter == sControlParameter)
{
returnValue = (Office.CommandBarControl)objPopUp.Controls[i];
return returnValue;
}
}
}

// --- 3. Lookup by ID (recursive search on parent bar) ---
if (iControlID > -1)
{
returnValue = (Office.CommandBarControl)objPopUp.Parent.FindControl(
Id: iControlID,
Recursive: true);

if (returnValue != null)
return returnValue;
}

// --- 4. Lookup by Caption (search only inside this popup) ---
if (sControlCaption.Length > 0)
{
for (int i = 1; i <= objPopUp.Controls.Count; i++)
{
if (objPopUp.Controls[i].Caption == sControlCaption)
{
returnValue = (Office.CommandBarControl)objPopUp.Controls[i];
return returnValue;
}
}
}
}
catch (Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message,
"",
false);
}

return returnValue;
}

CmdBar_LabelAdd

public void CmdBar_LabelAdd(
string sBarName,
string sLabelName,
int iLabelWidth = 40,
bool bBeginGroup = false,
bool bTemporary = false)
{
try
{
if (gbEND_GENERAL)
return;

// The original VBA implementation is commented out.
// I am preserving that exactly.

/*
var btn = mCommandBars[sBarName].Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Temporary: clsOfficeCore.TriStateFromBool(bTemporary));

btn.Tag = sLabelName;
btn.Caption = sLabelName;
btn.Width = iLabelWidth;
btn.BeginGroup = bBeginGroup;
*/
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"LabelAdd",
msCLASSNAME,
"add the label '" + sLabelName + "'" +
" to the command bar called '" + sBarName + "'",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ToolbarCreate

public void CmdBar_ToolbarCreate(
string sBarName,
bool bIsItVisible = true,
Office.MsoBarPosition objmsobarposition = Office.MsoBarPosition.msoBarFloating,
bool bTemporary = false)
{
Office.CommandBar objCommandBar = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ToolbarCreate");
return;
}

if (!ToolbarExists(sBarName))
{
objCommandBar = mCommandBars.Add(
Name: sBarName,
Position: objmsobarposition,
MenuBar: false,
Temporary: bTemporary);

objCommandBar.Visible = bIsItVisible;

objCommandBar.Protection =
Office.MsoBarProtection.msoBarNoCustomize |
Office.MsoBarProtection.msoBarNoResize;
}
else
{
clszMessagesGeneral.ToolbarAlreadyExistsInformation(sBarName);

ToolbarDelete(sBarName);
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objCommandBar = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ToolbarCreate",
msCLASSNAME,
"create the '" + objmsobarposition.ToString() +
"' command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ToolbarDelete

public void CmdBar_ToolbarDelete(
string sBarName,
bool bJustControls = false,
bool bInformUser = true)
{
Office.CommandBar objCommandBar = null;

try
{
if (gbEND_GENERAL)
return;

objCommandBar = ToolbarGet(sBarName);

if (objCommandBar == null)
{
if (bInformUser)
{
clszMessagesGeneral.ToolbarHasAlreadyBeenDeletedInformation(sBarName);
}
}
else
{
if (!bJustControls)
{
objCommandBar.Delete();
}
else
{
ControlsDelete(sBarName);
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objCommandBar = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ToolbarDelete",
msCLASSNAME,
"delete the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ToolbarExists

public bool CmdBar_ToolbarExists(
string sBarName,
bool bInformUserExists = false,
bool bInformUserDoesntExist = false)
{
Office.CommandBar objCommandBar = null;
bool returnValue = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("ToolbarExists");
return false;
}

returnValue = false;

foreach (Office.CommandBar bar in mCommandBars)
{
if (bar.Name == sBarName)
{
returnValue = true;

if (bInformUserExists)
{
clszMessagesGeneral.ToolbarAlreadyExistsInformation(sBarName);
}

break;
}
}

if (!returnValue && bInformUserDoesntExist)
{
clszMessagesGeneral.ToolbarDoesNotExistInformation(sBarName);
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objCommandBar = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ToolbarExists",
msCLASSNAME,
"determine if a command bar called '" + sBarName + "' currently exists.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ToolbarGet

public Office.CommandBar CmdBar_ToolbarGet(string sBarName)
{
Office.CommandBar objCommandBar = null;
Office.CommandBar returnValue = null;

try
{
if (gbEND_GENERAL)
return null;

if (mCommandBars == null)
{
CommandBarsIsNothing("ToolbarGet");
return null;
}

foreach (Office.CommandBar bar in mCommandBars)
{
if (bar.Name == sBarName)
{
returnValue = bar;
break;
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objCommandBar = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
// VBA forces the function result to Nothing when an error occurs
returnValue = null;

clsError.Handle(
"ToolbarGet",
msCLASSNAME,
"return the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_ToolbarReset

public void CmdBar_ToolbarReset(
string sBarName,
bool bCheckToolbarExists = false)
{
try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ToolbarReset");
return;
}

if (bCheckToolbarExists)
{
if (!ToolbarExists(sBarName, true))
return;
}

mCommandBars[sBarName].Reset();
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"CmdBar_ToolbarReset",
msCLASSNAME,
"reset the command bar '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ToolbarShow

public void CmdBar_ToolbarShow(string sBarName, bool bShowIt)
{
try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("ToolbarShow");
return;
}

// Match VBA logic exactly:
// Only change visibility when the requested state differs
if (bShowIt && !mCommandBars[sBarName].Visible)
{
mCommandBars[sBarName].Visible = true;
}
else if (!bShowIt && mCommandBars[sBarName].Visible)
{
mCommandBars[sBarName].Visible = false;
}
else
{
// VBA has an empty Else block — preserved intentionally
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ToolbarShow",
msCLASSNAME,
"display the command bar called '" + sBarName + "'.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_ToolbarVisible

public bool CmdBar_ToolbarVisible(string sBarName)
{
bool returnValue = false;

try
{
if (gbEND_GENERAL)
return false;

if (mCommandBars == null)
{
CommandBarsIsNothing("ToolbarVisible");
return false;
}

returnValue = mCommandBars[sBarName].Visible;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"ToolbarVisible",
msCLASSNAME,
"determine if the command bar called '" + sBarName + "' is visible.",
mobjCOMException,
mobjException);
}
}

return returnValue;
}

CmdBar_zExcelCOMAddinsButton

public void CmdBar_zExcelCOMAddinsButton()
{
Office.CommandBarPopup objToolsDropdownPopup = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("zExcelCOMAddinsButton");
return;
}

objToolsDropdownPopup =
(Office.CommandBarPopup)mCommandBars["Worksheet Menu Bar"]
.Controls["Tools"];

// Match VBA's 1-based enumeration
for (int i = 1; i <= objToolsDropdownPopup.Controls.Count; i++)
{
if (objToolsDropdownPopup.Controls[i].Id == 943)
{
// Check the next control
if (objToolsDropdownPopup.Controls[i + 1].Id != 3754)
{
objToolsDropdownPopup.Controls.Add(
Id: 3754,
Temporary: false,
Before: i + 1);

// MsgBox suppressed in original code
}
else
{
// Already added — MsgBox suppressed in original code
}
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objToolsDropdownPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"zExcelCOMAddinsButton",
msCLASSNAME,
"add the COM Addins button to the Tools drop-down menu.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_zMenuBarsReset

public void CmdBar_zMenuBarsReset()
{
try
{
if (gbEND_GENERAL)
return;

foreach (Office.CommandBar cmdbar in mCommandBars)
{
switch (cmdbar.Type)
{
case Office.MsoBarType.msoBarTypeMenuBar:
cmdbar.Reset();
break;
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"zMenuBarsReset",
msCLASSNAME,
"reset all the toolbars.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_zPowerPointCOMAddinsButton

public void CmdBar_zPowerPointCOMAddinsButton()
{
Office.CommandBarPopup objToolsDropdownPopup = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("zPowerPointCOMAddinsButton");
return;
}

objToolsDropdownPopup =
(Office.CommandBarPopup)mCommandBars["Menu Bar"]
.Controls["Tools"];

// Match VBA's 1-based enumeration
for (int i = 1; i <= objToolsDropdownPopup.Controls.Count; i++)
{
if (objToolsDropdownPopup.Controls[i].Id == 943)
{
// Check the next control
if (objToolsDropdownPopup.Controls[i + 1].Id != 3754)
{
objToolsDropdownPopup.Controls.Add(
Id: 3754,
Temporary: false,
Before: i + 1);

// MsgBox suppressed in original code
}
else
{
// Already added — MsgBox suppressed in original code
}
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objToolsDropdownPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"zPowerPointCOMAddinsButton",
msCLASSNAME,
"add the COM Addins button to the Tools drop-down menu.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_zShortcutMenuAddIdentifier

public void CmdBar_zShortcutMenuAddIdentifier(
Office.CommandBar objCommandBar)
{
Office.CommandBarButton objButton = null;

try
{
if (gbEND_GENERAL)
return;

objButton = (Office.CommandBarButton)objCommandBar.Controls.Add(
Type: Office.MsoControlType.msoControlButton,
Temporary: Office.MsoTriState.msoFalse,
Before: 1);

objButton.FaceId = 59;
objButton.Caption = objCommandBar.Name + " - " + objCommandBar.Index;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objButton = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"zShortcutMenuAddIdentifier",
msCLASSNAME,
"identify and label all the shortcut menus.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_zShortcutMenusIdentify

public void CmdBar_zShortcutMenusIdentify()
{
Office.CommandBar cmdbar = null;

try
{
if (gbEND_GENERAL)
return;

foreach (Office.CommandBar bar in mCommandBars)
{
if (bar.Name != "System" &&
bar.Type == Office.MsoBarType.msoBarTypePopup)
{
this.zShortcutMenuAddIdentifier(bar);
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
cmdbar = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"zShortcutMenusIdentify",
msCLASSNAME,
"identify and label all the shortcut menus.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_zShortcutMenusReset

public void CmdBar_zShortcutMenusReset()
{
try
{
if (gbEND_GENERAL)
return;

foreach (Office.CommandBar cmdbar in mCommandBars)
{
switch (cmdbar.Type)
{
case Office.MsoBarType.msoBarTypePopup:
cmdbar.Reset();
break;
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"zShortcutMenusReset",
msCLASSNAME,
"reset all the shortcut menus.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_zToolbarsReset

public void CmdBar_zToolbarsReset()
{
try
{
if (gbEND_GENERAL)
return;

foreach (Office.CommandBar cmdbar in mCommandBars)
{
switch (cmdbar.Type)
{
case Office.MsoBarType.msoBarTypeNormal:
cmdbar.Reset();
break;
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"zToolbarsReset",
msCLASSNAME,
"reset all the toolbars.",
mobjCOMException,
mobjException);
}
}
}

CmdBar_zWordCOMAddinsButton

public void CmdBar_zWordCOMAddinsButton()
{
Office.CommandBarPopup objToolsDropdownPopup = null;

try
{
if (gbEND_GENERAL)
return;

if (mCommandBars == null)
{
CommandBarsIsNothing("zWordCOMAddinsButton");
return;
}

objToolsDropdownPopup =
(Office.CommandBarPopup)mCommandBars["Menu Bar"]
.Controls["Tools"];

// Match VBA's 1-based indexing
for (int i = 1; i <= objToolsDropdownPopup.Controls.Count; i++)
{
if (objToolsDropdownPopup.Controls[i].Id == 751)
{
if (objToolsDropdownPopup.Controls[i + 1].Id != 3754)
{
objToolsDropdownPopup.Controls.Add(
Id: 3754,
Temporary: false,
Before: i + 1);

// MsgBox suppressed in original code
}
else
{
// Already added — MsgBox suppressed in original code
}
}
}
}
catch (System.Runtime.InteropServices.COMException comEx)
{
mobjCOMException = comEx;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
objToolsDropdownPopup = null;

if (gbDEBUG_ERRMSG_GENERAL ||
mobjCOMException != null ||
mobjException != null)
{
clsError.Handle(
"zWordCOMAddinsButton",
msCLASSNAME,
"add the COM Addins button to the Tools drop-down menu.",
mobjCOMException,
mobjException);
}
}
}

Message_CommandBar_DoesNotExist

public void Message_CommandBarDoesNotExist(
string sBarName)
{
string sMessage = $"The commandbar '{sBarName}' does not exist.";

System.Windows.Forms.MessageBox.Show(
sMessage,
Properties.Settings.Default.APP_WINFORMS_TITLE,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);

// Append method name
sMessage += $" ({System.Reflection.MethodBase.GetCurrentMethod().Name})";

// Clean whitespace and send to tracer
string cleaned = sMessage
.Replace(System.Environment.NewLine, " ")
.Replace(" ", " ");

Tracer_Add2("MESSAGE", cleaned);
}

Message_CommandBar_DropDownControlDoesNotExist

public void Message_CommandBarDropDownControlDoesNotExist(
System.Reflection.MethodBase objMethodBase,
Office.CommandBarPopup objDropDownPopUp,
string sControlTag,
string sControlParameter,
int iControlID,
string sControlCaption,
bool bFlagError = false,
bool bInformUser = true)
{
// Extract method/class info
string sSubroutineName = objMethodBase.Name;
string sDeclaringType = objMethodBase.DeclaringType.ToString();

// Extract class name after the first dot
string sClassName = sDeclaringType.Substring(sDeclaringType.IndexOf('.') + 1);

// Build message
string sMessage =
"This control does not exist on the '" + objDropDownPopUp.Caption + "' drop-down :" +
Environment.NewLine + Environment.NewLine +
"Tag: '" + sControlTag + "'" + Environment.NewLine +
"Parameter: '" + sControlParameter + "'" + Environment.NewLine +
"ID: '" + iControlID + "'" + Environment.NewLine +
"Caption: '" + sControlCaption + "'";

// Call your existing warning handler
modMessages.Exception_Warning(objMethodBase, sMessage);

// Update settings
Properties.Settings.Default.ERROR_OCCURRED = bFlagError;
}

Message_CommandBar_DropDownExtendControlDoesNotExist

public void Message_CommandBarDropDownExtendControlDoesNotExist(
System.Reflection.MethodBase objMethodBase,
Office.CommandBarPopup objDropDownPopUp,
string sExtensionTag,
string sExtensionParameter,
int iExtensionID,
string sExtensionCaption,
bool bFlagError = false,
bool bInformUser = true)
{
// Extract method/class info
string sSubroutineName = objMethodBase.Name;
string sDeclaringType = objMethodBase.DeclaringType.ToString();

// Extract class name after the first dot
string sClassName = sDeclaringType.Substring(sDeclaringType.IndexOf('.') + 1);

// Build message
string sMessage =
"This extension bar does not exist on the '" + objDropDownPopUp.Caption + "' drop-down :" +
Environment.NewLine + Environment.NewLine +
"Tag: '" + sExtensionTag + "'" + Environment.NewLine +
"Parameter: '" + sExtensionParameter + "'" + Environment.NewLine +
"ID: '" + iExtensionID + "'" + Environment.NewLine +
"Caption: '" + sExtensionCaption + "'";

// Call your existing warning handler
modMessages.Exception_Warning(objMethodBase, sMessage);

// Update settings
Properties.Settings.Default.ERROR_OCCURRED = bFlagError;
}

Message_CommandBar_HandlerNotInList

public void Message_CommandBarHandlerNotInList(
System.Reflection.MethodBase objMethodBase,
string sParameter,
string sHandlerTag)
{
// Extract method/class info
string sSubroutineName = objMethodBase.Name;
string sDeclaringType = objMethodBase.DeclaringType.ToString();

// Extract class name after the first dot
string sClassName = sDeclaringType.Substring(sDeclaringType.IndexOf('.') + 1);

// Build message
string sMessage =
"The parameter '" + sParameter + "' associated with this button has not been added to the Select/Case list." +
Environment.NewLine + Environment.NewLine +
"This needs to be added to the handler associated with all the buttons with the following tag: '" +
sHandlerTag + "'.";

// Show message box
System.Windows.Forms.MessageBox.Show(
sMessage,
Properties.Settings.Default.APP_WINFORMS_TITLE,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);

// Append method name
sMessage += $" ({System.Reflection.MethodBase.GetCurrentMethod().Name})";

// Clean whitespace and send to tracer
string cleaned = sMessage
.Replace(Environment.NewLine, " ")
.Replace(" ", " ");

Tracer_Add2("MESSAGE", cleaned);
}

Message_CommandBar_ToolbarsRefreshed

public void Message_CommandBarToolbarsRefreshed()
{
string sMessage =
"The following interface items have been refreshed:" +
Environment.NewLine + Environment.NewLine +
"Menu: 'File > New Doc'" + Environment.NewLine +
"Toolbar: '" + Properties.Settings.Default.APP_TOOLBAR_MAIN_NAME + "'" + Environment.NewLine +
"Toolbar: '" + Properties.Settings.Default.APP_TOOLBAR_FORMATTING_NAME + "'" + Environment.NewLine +
"Toolbar: '" + Properties.Settings.Default.APP_TOOLBAR_REVIEWING_NAME + "'" + Environment.NewLine +
"Toolbar: '" + Properties.Settings.Default.APP_TOOLBAR_COMPILER_NAME + "'";

// Show message box
System.Windows.Forms.MessageBox.Show(
sMessage,
Properties.Settings.Default.APP_WINFORMS_TITLE + " - Refresh FICC Interface",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);

// Append method name
sMessage += $" ({System.Reflection.MethodBase.GetCurrentMethod().Name})";

// Clean whitespace and send to tracer
string cleaned = sMessage
.Replace(Environment.NewLine, " ")
.Replace(" ", " ");

Tracer_Add2("MESSAGE", cleaned);
}

Message_CommandBarsReferenceIsNothing

public static void Message_CommandBarsReferenceIsNothing(string sProcedureName)
{
// If an error has already been flagged, exit immediately
if (clsError.ErrorFlag())
return;

System.Windows.Forms.MessageBox.Show(
"The reference to the object 'mCommandBars' " +
"in the procedure '" + sProcedureName + "' has been lost.",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation
);

// Set the error flag
clsError.ErrorFlagChange(true);
}

Message_MenuExtensionDoesNotExist

public static void Message_MenuExtensionDoesNotExist(
string sProcedureName,
string sBarName,
string sPopUpTag = "",
string sPopUpParameter = "",
int iPopUpID = -1,
string sPopUpCaption = "",
string sExtensionTag = "",
string sExtensionParameter = "",
int iExtensionID = -1,
string sExtensionCaption = "",
bool bFlagError = false)
{
// If an error has already been flagged, exit immediately
if (clsError.ErrorFlag())
return;

string sMessage =
"The extension with" + Environment.NewLine + Environment.NewLine +
"Tag '" + sExtensionTag + "'" + Environment.NewLine +
"Parameter '" + sExtensionParameter + "'" + Environment.NewLine +
"ID '" + iExtensionID + "'" + Environment.NewLine +
"Caption '" + sExtensionCaption + "'" + Environment.NewLine + Environment.NewLine +
"does not exist on the popup with" + Environment.NewLine +
"Tag '" + sPopUpTag + "'" + Environment.NewLine +
"Parameter '" + sPopUpParameter + "'" + Environment.NewLine +
"ID '" + iPopUpID + "'" + Environment.NewLine +
"Caption '" + sPopUpCaption + "'" + Environment.NewLine + Environment.NewLine +
"on the command bar called '" + sBarName + "'.";

clsError.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
null,
sMessage,
null,
false
);
}

Message_MenuPopUpDoesNotExist

public static void Message_MenuPopUpDoesNotExist(
string sProcedureName,
string sBarName,
string sPopUpTag = "",
string sPopUpParameter = "",
int iPopUpID = -1,
string sPopUpCaption = "",
bool bFlagError = false)
{
// If an error has already been flagged, exit immediately
if (clsError.ErrorFlag())
return;

string sMessage =
"The popup menu with" + Environment.NewLine + Environment.NewLine +
"Tag '" + sPopUpTag + "'" + Environment.NewLine +
"Parameter '" + sPopUpParameter + "'" + Environment.NewLine +
"ID '" + iPopUpID + "'" + Environment.NewLine +
"Caption '" + sPopUpCaption + "'" + Environment.NewLine + Environment.NewLine +
"does not exist on the command bar called '" + sBarName + "'.";

clsError.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
null,
sMessage,
null,
false
);
}

Message_ReferenceCommandBarsIsNothingExclamation

public static void Message_ReferenceCommandBarsIsNothingExclamation(
string sProcedureName)
{
// If an error has already been flagged, exit immediately
if (clsError.ErrorFlag())
return;

System.Windows.Forms.MessageBox.Show(
"The reference to the object 'mCommandBars' " +
"in the procedure '" + sProcedureName + "' has been lost.",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation
);

// Set the error flag
clsError.ErrorFlagChange(true);
}

Message_RibbonDoesNotExist

public void Message_RibbonDoesNotExist(
string sRibbonName)
{
string sMessage = $"The ribbon was name '{sRibbonName}' does not exist.";

System.Windows.Forms.MessageBox.Show(
sMessage,
Properties.Settings.Default.APP_WINFORMS_TITLE + " - Ribbon Exists",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);

// Append method name
sMessage += $" ({System.Reflection.MethodBase.GetCurrentMethod().Name})";

// Clean whitespace and send to tracer
string cleaned = sMessage
.Replace(Environment.NewLine, " ")
.Replace(" ", " ");

Tracer_Add2("MESSAGE", cleaned);
}

Message_ToolbarAlreadyExists

public static void Message_ToolbarAlreadyExists(
string sBarName,
bool bDeleteToolbar = false,
bool bFlagError = false)
{
// If you want to preserve the commented-out VBA early exit,
// leave it commented here as well:
// if (clsError.ErrorFlag()) return;

if (!bDeleteToolbar)
{
System.Windows.Forms.MessageBox.Show(
"The toolbar '" + sBarName + "' already exists.",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);
}
else
{
System.Windows.Forms.MessageBox.Show(
"The toolbar '" + sBarName + "' already exists." +
Environment.NewLine +
"This will be deleted.",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);
}

// Set the error flag
clsError.ErrorFlagChange(bFlagError);
}

Message_ToolbarBuiltInControlDoesNotExist

public static void Message_ToolbarBuiltInControlDoesNotExist(
int iControlID,
string sControlCaption,
bool bFlagError = false)
{
// Exit early if an error has already been flagged
if (clsError.ErrorFlag())
return;

System.Windows.Forms.MessageBox.Show(
"The control with " +
"ID: '" + iControlID + "' and " +
"Caption: '" + sControlCaption + "' " +
Environment.NewLine +
"is not a recognised built-in command.",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Warning
);

// Set the error flag
clsError.ErrorFlagChange(bFlagError);
}

Message_ToolbarButtonNoMacro

public static void Message_ToolbarButtonNoMacro(
bool bFlagError = false)
{
// If you want to preserve the commented-out VBA early exit,
// leave it commented here as well:
// if (clsError.ErrorFlag()) return;

System.Windows.Forms.MessageBox.Show(
"This command has not been written yet." +
Environment.NewLine + Environment.NewLine +
"What would you like this command to do ?",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Question
);

// Set the error flag
clsError.ErrorFlagChange(bFlagError);
}

Message_ToolbarControlDoesNotExist

public static void Message_ToolbarControlDoesNotExist(
string sProcedureName,
string sBarName,
string sControlTag,
string sControlParameter,
int iControlID,
string sControlCaption,
bool bFlagError = false)
{
// Exit early if an error has already been flagged
if (clsError.ErrorFlag())
return;

System.Windows.Forms.MessageBox.Show(
"The control with" + Environment.NewLine + Environment.NewLine +
"Tag: '" + sControlTag + "'" + Environment.NewLine +
"Parameter: '" + sControlParameter + "'" + Environment.NewLine +
"ID: '" + iControlID + "'" + Environment.NewLine +
"Caption: '" + sControlCaption + "'" + Environment.NewLine + Environment.NewLine +
"does not exist on the command bar called '" + sBarName + "'.",
gobjSolution.SolutionFormPrefix + sProcedureName,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Warning
);

// Set the error flag
clsError.ErrorFlagChange(bFlagError);
}

Message_ToolbarDoesNotExist

public static void Message_ToolbarDoesNotExist(
string sBarName,
bool bFlagError = false)
{
// If you want to preserve the commented-out VBA early exit,
// leave it commented here as well:
// if (clsError.ErrorFlag()) return;

System.Windows.Forms.MessageBox.Show(
"The toolbar '" + sBarName + "' does not exist.",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);

// Set the error flag
clsError.ErrorFlagChange(bFlagError);
}

Message_ToolbarExtensionDoesNotExist

public static void Message_ToolbarExtensionDoesNotExist(
string sProcedureName,
string sBarName,
string sExtensionCaption = "",
string sExtensionTag = "",
bool bFlagError = false)
{
// Exit early if an error has already been flagged
if (clsError.ErrorFlag())
return;

string sMessage = "";

if (sExtensionCaption.Length == 0)
{
sMessage =
"The extension with the tag '" + sExtensionTag + "' does not exist " +
"on the command bar called '" + sBarName + "'.";
}

if (sExtensionTag.Length == 0)
{
sMessage =
"The extension with the caption '" + sExtensionCaption + "' does not exist " +
"on the command bar called '" + sBarName + "'.";
}

clsError.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
null,
sMessage,
null,
false
);
}

Message_ToolbarHasAlreadyBeenDeleted

public static void Message_ToolbarHasAlreadyBeenDeleted(
string sBarName,
bool bFlagError = false)
{
// If you want to preserve the commented-out VBA early exit,
// leave it commented here as well:
// if (clsError.ErrorFlag()) return;

System.Windows.Forms.MessageBox.Show(
"The toolbar '" + sBarName + "' has already been deleted.",
gobjSolution.SolutionFormTitle,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);

// Set the error flag
clsError.ErrorFlagChange(bFlagError);
}

OfficeRibbon_Return

public Microsoft.Office.Tools.Ribbon.OfficeRibbon OfficeRibbon_Return(
string sRibbonName,
bool bInformUser = true)
{
try
{
modGeneral.Tracer_AddSubroutineStart(
System.Reflection.MethodBase.GetCurrentMethod()
);

Microsoft.Office.Tools.Ribbon.OfficeRibbon objRibbon;

for (int i = 1; i <= Globals.Ribbons.Count; i++)
{
objRibbon = Globals.Ribbons.Item(i);

if (objRibbon.Name == sRibbonName)
{
return objRibbon;
}
}

if (bInformUser)
{
Message_General_RibbonDoesNotExist(sRibbonName);
}
}
catch (System.Exception ex)
{
modMessages.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex
);
}

return null;
}

Sep___Menu

public static string Sep___Menu(
int iIndent,
string sMenuName,
int SeparatorNo,
string sTitle,
string sGetTitle,
bool bVisible,
string sGetVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sTitle.Length > 0) { colArguments.Add("title"); }
if (sGetTitle.Length > 0) { colArguments.Add("getTitle"); }
if (bVisible == false) { colArguments.Add("visible"); }
if (sGetVisible.Length > 0) { colArguments.Add("getVisible"); }

sreturn += String.Empty.PadLeft(iIndent) + " sreturn += @" id=""" + sMenuName + "MenuSeparator" + SeparatorNo + @"""";
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += clsRibbon.Tag_Attribute_String(14, ref colArguments, "title", sTitle);
sreturn += clsRibbon.Tag_Attribute_String(14, ref colArguments, "getTitle", sGetTitle);
sreturn += clsRibbon.Tag_Attribute_Boolean(14, ref colArguments, "visible", bVisible);
sreturn += clsRibbon.Tag_Attribute_String(14, ref colArguments, "getVisible", sGetVisible);

sreturn += @"/>";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Sep__Bar

public static string Sep__Bar(
int iIndent,
string sToolbarName,
int iSeparatorNo,
bool bVisible)
{
string sreturn = "";

try
{
sreturn += String.Empty.PadLeft(iIndent) + " sreturn += @" id=""" + sToolbarName + @"ToolbarSaperator" + iSeparatorNo + @"""";

if (bVisible == false)
{
sreturn += String.Empty.PadLeft(iIndent + 10) + @"visible=""false""";
sreturn += System.Environment.NewLine;
}
sreturn += String.Empty.PadLeft(iIndent) + @"/>";
sreturn += System.Environment.NewLine;

return sreturn;

}
catch { return ""; }
finally { }
}

Tab_Select

public void Tab_Select(
string sTabName)
{
try
{
modGeneral.Tracer_AddSubroutineStart(
System.Reflection.MethodBase.GetCurrentMethod()
);

// Get the top-level IAccessible window for the current process
Microsoft.Office.Core.IAccessible objTopWindow =
MSAAHelper.GetAccessibleObjectFromHandle(
System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle
);

// Get the IAccessible object for the Ribbon property page
Microsoft.Office.Core.IAccessible objAccessibleRibbon =
MSAAHelper.GetAccessibleObjectByNameAndRole(
objTopWindow,
new System.Text.RegularExpressions.Regex("Ribbon"),
"property page",
false
);

// Get the Ribbon Tabs container
Microsoft.Office.Core.IAccessible[] objAccessibleChildren =
MSAAHelper.GetAccessibleChildren(
MSAAHelper.GetAccessibleObjectByNameAndRole(
objAccessibleRibbon,
new System.Text.RegularExpressions.Regex("Ribbon Tabs"),
"page tab list",
true
)
);

// Iterate through visible ribbon tabs
foreach (Microsoft.Office.Core.IAccessible objAccessibleChild in objAccessibleChildren)
{
if (objAccessibleChild.accChildCount > 0)
{
Microsoft.Office.Core.IAccessible[] objAccessibleTabs =
MSAAHelper.GetAccessibleChildren(objAccessibleChild);

foreach (Microsoft.Office.Core.IAccessible objAccessibleTab in objAccessibleTabs)
{
string state = Ribbon_GetStateText(objAccessibleTab.accState[0]);

if (objAccessibleTab.accName[0] == sTabName)
{
objAccessibleTab.accDoDefaultAction(0);
return;
}
}
}
}
}
catch (System.Exception ex)
{
modMessages.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex
);
}
}

Tag_Attribute_Boolean

private static string Tag_Attribute_Boolean(
int iIndent,
ref System.Collections.Generic.List colArguments,
string sStringTag,
bool bBooleanValue)
{
string sreturn = "";

try
{
if (bBooleanValue == false)
{
colArguments.Remove(sStringTag);
sreturn += String.Empty.PadLeft(iIndent) + sStringTag + @"=""" + bBooleanValue + @"""";
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }
}
return sreturn;
}
catch (System.Exception objException)
{
return "";
}
}

Tag_Attribute_String

private static string Tag_Attribute_String(
int iIndent,
ref System.Collections.Generic.List colArguments,
string sStringTag,
string sStringContents)
{
string sreturn = "";

try
{
if (sStringContents.Length > 0)
{
colArguments.Remove(sStringTag);
sreturn += String.Empty.PadLeft(iIndent) + sStringTag + @"=""" + sStringContents + @"""";
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }
}
return sreturn;
}
catch (System.Exception objException)
{
return "";
}
}

Tag_Box

public static string Tag_Box(
int iIndent,
string sID,
bool bVertical)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (bVertical == true) { colArguments.Add("vertical"); }

sreturn += String.Empty.PadLeft(iIndent) + " sreturn += @" id=""" + sID + @"""";

if (bVertical == false)
{
sreturn += System.Environment.NewLine;
sreturn += String.Empty.PadLeft(iIndent + 4) + @" boxstyle=""horizontal""";
}
else
{
colArguments.Remove("vertical");
sreturn += System.Environment.NewLine;
sreturn += String.Empty.PadLeft(iIndent + 4) + @" boxstyle=""vertical""";
}

sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_Button

public static string Tag_Button(
int iIndent,
string sIDMso,
string sLabel,
string sID,
string sImageMso,
string sImage,
string sSize,
string sGetEnabled,
string sScreentip,
bool bShowLabel,
bool bShowImage,
string sSupertip,
string sDescription,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sIDMso.Length > 0) { colArguments.Add("idMso"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sID.Length > 0) { colArguments.Add("id"); }
if (sImageMso.Length > 0) { colArguments.Add("imageMso"); }
if (sImage.Length > 0) { colArguments.Add("image"); }
if (sSize.Length > 0) { colArguments.Add("size"); }
if (sGetEnabled.Length > 0) { colArguments.Add("getEnabled"); }
if (sScreentip.Length > 0) { colArguments.Add("screentip"); }
if (sSupertip.Length > 0) { colArguments.Add("supertip"); }
if (bShowLabel == false) { colArguments.Add("showLabel"); }
if (bShowImage == false) { colArguments.Add("showImage"); }
if (sDescription.Length > 0) { colArguments.Add("description"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
if (sIDMso.Length > 0)
{
colArguments.Remove("sIDMso");
sreturn += @" idMso=""" + sIDMso + @"""";
}
else
{
if (sID.Length == 0)
{
sreturn += String.Empty.PadLeft(iIndent + 7) + @" onAction=""Button_" + sLabel.Replace(" ", "") + @"""";
}
else
{
colArguments.Remove("sID");
sreturn += @" id=""" + sID + @"""" + System.Environment.NewLine;
sreturn += String.Empty.PadLeft(iIndent + 7) + @" onAction=""Button_" + sID + @"""";
}
}
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "imageMso", sImageMso);
sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "image", sImage);
sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "size", sSize);
sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "getEnabled", sGetEnabled);

if (sLabel.Length > 0)
{
colArguments.Remove("label");
sreturn += String.Empty.PadLeft(iIndent + 7) + @"= label=""" + sLabel + @"""";

if (sLabel.Length > 7)
{
if (sLabel.Substring(0, 7) != "MISSING")
{
sreturn += System.Environment.NewLine;
sreturn += String.Empty.PadLeft(iIndent + 7) + @" enabled=""false""";
}
}

if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }
}

sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "screentip", sScreentip);
sreturn += clsRibbon.Tag_Attribute_Boolean(7, ref colArguments, "showLabel", bShowLabel);
sreturn += clsRibbon.Tag_Attribute_Boolean(7, ref colArguments, "showImage", bShowImage);
sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "supertip", sSupertip);
sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "description", sDescription);
sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(7, ref colArguments, "visible", bVisible);

sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_ButtonGroup

public static string Tag_ButtonGroup(
int iIndent,
string sID,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sID.Length > 0) { colArguments.Add("id"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "id", sID);
sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(7, ref colArguments, "visible", bVisible);

sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_CheckBox

public static string Tag_CheckBox(
int iIndent,
string sIDMso,
string sLabel,
string sID,
string sScreentip,
string sSupertip,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sIDMso.Length > 0) { colArguments.Add("idMso"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sID.Length > 0) { colArguments.Add("id"); }
if (sScreentip.Length > 0) { colArguments.Add("screentip"); }
if (sSupertip.Length > 0) { colArguments.Add("supertip"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "


sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "label", sLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "screentip", sScreentip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "supertip", sSupertip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

sreturn += @"/>";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_ComboBox

public static string Tag_ComboBox(
int iIndent,
string sID,
string sSizeString,
string sScreentip,
string sSupertip,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sID.Length > 0) { colArguments.Add("id"); }
if (sSizeString.Length > 0) { colArguments.Add("sizeString"); }
if (sScreentip.Length > 0) { colArguments.Add("screentip"); }
if (sSupertip.Length > 0) { colArguments.Add("supertip"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
if (sID.Length > 0)
{
colArguments.Remove("sID");
sreturn += @" id=""" + sID + @"""" + System.Environment.NewLine;

sreturn += String.Empty.PadLeft(iIndent + 9) + @" onAction=""ComboBox_" + sID + @"""";
}
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "sizeString", sSizeString);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "screentip", sScreentip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "supertip", sSupertip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

sreturn += @"/>";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_Control

public static string Tag_Control(
int iIndent,
string sIDMso,
string sLabel,
bool bShowLabel)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sIDMso.Length > 0) { colArguments.Add("idMso"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (bShowLabel == false) { colArguments.Add("showLabel"); }

sreturn += String.Empty.PadLeft(iIndent) + "
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "idMso", sIDMso);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "label", sLabel);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showLabel", bShowLabel);

sreturn += @"/>";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_CustomUI

private static string Tag_CustomUI(
string sVersion,
bool bInStudio,
bool bUseLoadImageCallback)
{
string sreturn = "";
string sschema = "";

try
{
if (bInStudio == true)
{
sreturn += @"" + System.Environment.NewLine;
}

if (sVersion == "2007") { sschema = @"http://schemas.microsoft.com/office/2006/01/customui"; }
if (sVersion == "2010") { sschema = @"http://schemas.microsoft.com/office/2009/07/customui"; }

sreturn += @"
if (bInStudio == true)
{
sreturn += System.Environment.NewLine + @" onLoad=""Ribbon_Load""";
}
if (bUseLoadImageCallback == true)
{
sreturn += System.Environment.NewLine + @" loadImage=""Callback_LoadImage""";
}
sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_DropDown

public static string Tag_DropDown(
int iIndent,
string sID,
string sSizeString,
string sScreentip,
string sSupertip,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sID.Length > 0) { colArguments.Add("id"); }
if (sSizeString.Length > 0) { colArguments.Add("sizeString"); }
if (sScreentip.Length > 0) { colArguments.Add("screentip"); }
if (sSupertip.Length > 0) { colArguments.Add("supertip"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
if (sID.Length > 0)
{
colArguments.Remove("sID");
sreturn += @" id=""" + sID + @"""" + System.Environment.NewLine;

sreturn += String.Empty.PadLeft(iIndent + 9) + @" onAction=""DropDown_" + sID + @"""";
}
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "sizeString", sSizeString);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "screentip", sScreentip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "supertip", sSupertip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_DynamicMenu

public static string Tag_DynamicMenu(
int iIndent,
string sIDMso,
string sLabel,
string sID,
string sImageMso,
string sImage,
string sGetContent,
bool bShowLabel,
bool bShowImage,
string sSize,
string sDescription,
string sScreentip,
string sSupertip,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sIDMso.Length > 0) { colArguments.Add("idMso"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sID.Length > 0) { colArguments.Add("id"); }
if (sImageMso.Length > 0) { colArguments.Add("imageMso"); }
if (sImage.Length > 0) { colArguments.Add("image"); }
if (sGetContent.Length > 0) { colArguments.Add("getContent"); }
if (bShowLabel == false) { colArguments.Add("showLabel"); }
if (bShowImage == false) { colArguments.Add("showImage"); }
if (sSize.Length > 0) { colArguments.Add("size"); }
if (sDescription.Length > 0) { colArguments.Add("description"); }
if (sScreentip.Length > 0) { colArguments.Add("screentip"); }
if (sSupertip.Length > 0) { colArguments.Add("supertip"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
if (sIDMso.Length > 0)
{
colArguments.Remove("sIDMso");
sreturn += @" id=Mso""" + sIDMso + @"""";
}
else
{
if (sID.Length == 0)
{
sreturn += @" id=""" + sLabel.Replace(" ", "") + @"""";
}
else
{
colArguments.Remove("sID");
sreturn += @" id=""" + sID + @"""";
}
}
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "label", sLabel);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showLabel", bShowLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "imageMso", sImageMso);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "image", sImage);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "getContent", sGetContent);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showLabel", bShowLabel);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showImage", bShowImage);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "size", sSize);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "description", sDescription);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "screentip", sScreentip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "supertip", sSupertip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_EditBox

public static string Tag_EditBox(
int iIndent,
string sID,
string sGetText,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sID.Length > 0) { colArguments.Add("id"); }
if (sGetText.Length > 0) { colArguments.Add("getText"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "getText", sGetText);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_End

private static string Tag_End(
int iIndent,
string sTag)
{
string sreturn = "";

try
{
if (sTag == "customUI")
{
sreturn += String.Empty.PadLeft(iIndent) + @"";
}
else
{
sreturn += String.Empty.PadLeft(iIndent) + @"";
sreturn += System.Environment.NewLine;
}

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_Gallery

public static string Tag_Gallery(
int iIndent,
string sIDMso,
string sID,
string sLabel,
string sSize,
bool bShowLabel,
int iItemHeight,
int iItemWidth,
int iRows,
int iCols)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sIDMso.Length > 0) { colArguments.Add("idMso"); }
if (sID.Length > 0) { colArguments.Add("id"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sSize.Length > 0) { colArguments.Add("size"); }
if (bShowLabel == false) { colArguments.Add("showLabel"); }
if (iItemHeight > -1) { colArguments.Add("itemHeight"); }
if (iItemWidth > -1) { colArguments.Add("itemWidth"); }
if (iRows > -1) { colArguments.Add("rows"); }
if (iCols > -1) { colArguments.Add("columns"); }

sreturn += String.Empty.PadLeft(iIndent) + "
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "idMso", sIDMso);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "id", sID);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "label", sLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "size", sSize);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showLabel", bShowLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "itemHeight", iItemHeight.ToString());
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "itemWidth", iItemWidth.ToString());
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "rows", iRows.ToString());
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "columns", iCols.ToString());

sreturn += @"/>";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_Group

private static string Tag_Group(
int iIndent,
string sID,
string sLabel,
string sGetVisible,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sGetVisible.Length > 0) { colArguments.Add("getVisible"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + " sreturn += @" id=""" + sID + @"""";
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += Tag_Attribute_String(iIndent + 7, ref colArguments, "label", sLabel);
sreturn += Tag_Attribute_String(iIndent + 7, ref colArguments, "getVisible", sGetVisible);
sreturn += Tag_Attribute_Boolean(iIndent + 7, ref colArguments, "visible", bVisible);

sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_ItemAdd

public static string Tag_ItemAdd(
int iIndent,
string sLabel,
string sID)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sID.Length > 0) { colArguments.Add("id"); }

sreturn += String.Empty.PadLeft(iIndent) + "
if (sID.Length > 0)
{
colArguments.Remove("sID");
sreturn += @" id=""" + sID + @"""";
}
else
{
sreturn += @" id=""" + sLabel.Replace(" ", "_") + @"""";
}
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += clsRibbon.Tag_Attribute_String(7, ref colArguments, "label", sLabel);

sreturn += @"/>";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_LabelControl

public static string Tag_LabelControl(
int iIndent,
string sID,
string sLabel,
bool bShowLabel,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sID.Length > 0) { colArguments.Add("id"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (bShowLabel == false) { colArguments.Add("showLabel"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "id", sID);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "label", sLabel);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showLabel", bShowLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

sreturn += @"/>";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_Menu

public static string Tag_Menu(
int iIndent,
string sIDMso,
string sLabel,
string sID,
string sImageMso,
string sImage,
bool bShowLabel,
bool bShowImage,
string sSize,
string sGetEnabled,
string sDescription,
string sScreentip,
string sSupertip,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sIDMso.Length > 0) { colArguments.Add("idMso"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sID.Length > 0) { colArguments.Add("id"); }
if (sImageMso.Length > 0) { colArguments.Add("imageMso"); }
if (sImage.Length > 0) { colArguments.Add("image"); }
if (bShowLabel == false) { colArguments.Add("showLabel"); }
if (bShowImage == false) { colArguments.Add("showImage"); }
if (sSize.Length > 0) { colArguments.Add("size"); }
if (sGetEnabled.Length > 0) { colArguments.Add("getEnabled"); }
if (sDescription.Length > 0) { colArguments.Add("description"); }
if (sScreentip.Length > 0) { colArguments.Add("screentip"); }
if (sSupertip.Length > 0) { colArguments.Add("supertip"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "idMso", sIDMso);

if (sIDMso.Length ==0)
{
if (sID.Length == 0)
{
sreturn += @" id=""" + sLabel.Replace(" ", "") + @"""";
}
else
{
colArguments.Remove("sID");
sreturn += @" id=""" + sID + @"""";
}
}
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "label", sLabel);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showLabel", bShowLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "imageMso", sImageMso);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "image", sImage);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showImage", bShowImage);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "getEnabled", sGetEnabled);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "size", sSize);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "description", sDescription);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "screentip", sScreentip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "supertip", sSupertip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

if (sIDMso.Length > 0) { sreturn += @"/>"; }
if (sIDMso.Length == 0) { sreturn += @">"; }

sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_Ribbon

private static string Tag_Ribbon(
int iIndent,
bool bStartFromScratch)
{
string sreturn = "";
string strueorfalse = "";

try
{
if (bStartFromScratch == true) { strueorfalse = "true"; }
if (bStartFromScratch == false) { strueorfalse = "false"; }

sreturn += String.Empty.PadLeft(iIndent) + @"";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_Separator

public static string Tag_Separator(
int iIndent,
string sID,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sID.Length > 0) { colArguments.Add("id"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "id", sID);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_SplitButton

public static string Tag_SplitButton(
int iIndent,
string sIDMso,
string sLabel,
string sID,
string sImageMso,
string sImage,
string sSize,
string sGetEnabled,
string sScreentip,
bool bShowLabel,
string sSupertip,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sIDMso.Length > 0) { colArguments.Add("idMso"); }
if (sID.Length > 0) { colArguments.Add("id"); }
if (sImageMso.Length > 0) { colArguments.Add("imageMso"); }
if (sImage.Length > 0) { colArguments.Add("image"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sSize.Length > 0) { colArguments.Add("size"); }
if (sGetEnabled.Length > 0) { colArguments.Add("getEnabled"); }
if (sScreentip.Length > 0) { colArguments.Add("screentip"); }
if (bShowLabel == false) { colArguments.Add("showLabel"); }
if (sSupertip.Length > 0) { colArguments.Add("supertip"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
if (sIDMso.Length > 0)
{
colArguments.Remove("sIDMso");
sreturn += @" idMso=""" + sIDMso + @"""";
}
else
{
if (sID.Length > 0)
{
colArguments.Remove("sID");
sreturn += @" id=""" + sID + @"""" + System.Environment.NewLine;
}
}
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "imageMso", sImageMso);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "image", sImage);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "label", sLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "size", sSize);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "getEnabled", sGetEnabled);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "screentip", sScreentip);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showLabel", bShowLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "supertip", sSupertip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

sreturn += @">";

return sreturn;
}
catch (System.Exception objException)
{
return "";
}
finally
{
}
}

Tag_Tab

private static string Tag_Tab(
int iIndent,
string sID,
string sIDMso,
string sLabel,
string sInsertAfterMso,
string sInsertBeforeMso,
string sTag,
string sGetVisible,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sIDMso.Length > 0) { colArguments.Add("idMso"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sInsertAfterMso.Length > 0) { colArguments.Add("insertAfterMso"); }
if (sInsertBeforeMso.Length > 0) { colArguments.Add("insertBeforeMso"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (sGetVisible.Length > 0) { colArguments.Add("getVisible"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + " sreturn += @" id=""" + sID + @"""";
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += Tag_Attribute_String(iIndent + 4, ref colArguments, "idMso", sIDMso);
sreturn += Tag_Attribute_String(iIndent + 4, ref colArguments, "label", sLabel);
sreturn += Tag_Attribute_String(iIndent + 4, ref colArguments, "insertAfterMso", sInsertAfterMso);
sreturn += Tag_Attribute_String(iIndent + 4, ref colArguments, "insertBeforeMso", sInsertBeforeMso);
sreturn += Tag_Attribute_String(iIndent + 4, ref colArguments, "tag", sTag);
sreturn += Tag_Attribute_String(iIndent + 4, ref colArguments, "getVisible", sGetVisible);
sreturn += Tag_Attribute_Boolean(iIndent + 4, ref colArguments, "visible", bVisible);

sreturn += @">";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_Tabs

private static string Tag_Tabs(
int iIndent)
{
string sreturn = "";

try
{
sreturn += String.Empty.PadLeft(iIndent) + "";
sreturn += System.Environment.NewLine;

return sreturn;
}
catch { return ""; }
finally { }
}

Tag_ToggleButton

public static string Tag_ToggleButton(
int iIndent,
string sIDMso,
string sLabel,
string sID,
string sImageMso,
string sImage,
string sSize,
string sGetEnabled,
string sScreentip,
bool bShowLabel,
string sSupertip,
string sTag,
bool bVisible)
{
string sreturn = "";
System.Collections.Generic.List colArguments = new System.Collections.Generic.List();

try
{
if (sIDMso.Length > 0) { colArguments.Add("idMso"); }
if (sID.Length > 0) { colArguments.Add("id"); }
if (sImageMso.Length > 0) { colArguments.Add("imageMso"); }
if (sImage.Length > 0) { colArguments.Add("image"); }
if (sLabel.Length > 0) { colArguments.Add("label"); }
if (sSize.Length > 0) { colArguments.Add("size"); }
if (sGetEnabled.Length > 0) { colArguments.Add("getEnabled"); }
if (sScreentip.Length > 0) { colArguments.Add("screentip"); }
if (bShowLabel == false) { colArguments.Add("showLabel"); }
if (sSupertip.Length > 0) { colArguments.Add("supertip"); }
if (sTag.Length > 0) { colArguments.Add("tag"); }
if (bVisible == false) { colArguments.Add("visible"); }

sreturn += String.Empty.PadLeft(iIndent) + "
if (sIDMso.Length > 0)
{
colArguments.Remove("sIDMso");
sreturn += @" idMso=""" + sIDMso + @"""";
}
else
{
if (sID.Length > 0)
{
colArguments.Remove("sID");
sreturn += @" id=""" + sID + @"""" + System.Environment.NewLine;
sreturn += String.Empty.PadLeft(iIndent + 13) + @" onAction=""ToggleButton_" + sID + @"""";
}
}
if (colArguments.Count > 0) { sreturn += System.Environment.NewLine; }

sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "imageMso", sImageMso);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "image", sImage);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "label", sLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "size", sSize);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "getEnabled", sGetEnabled);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "screentip", sScreentip);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "showLabel", bShowLabel);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "supertip", sSupertip);
sreturn += clsRibbon.Tag_Attribute_String(13, ref colArguments, "tag", sTag);
sreturn += clsRibbon.Tag_Attribute_Boolean(13, ref colArguments, "visible", bVisible);

sreturn += @">";

return sreturn;
}
catch (System.Exception objException)
{
return "";
}
finally
{
}
}

© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top