Word Interop
Selection.Font.Bold = -1 (True) / 0 (False)
Selection.Font.Italic = -1 (True) / 0 (False)
Selection.Font.Superscript = -1 (True) / 0 (False)
Selection.Tables(1).Rows.WrapAroundText = -1 (True) / 0 (False)
Selection.Tables(1).Rows.AllowOverlap = -1 (True) / 0 (False)
ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = -1 (True) / 0 (False)
Application.ActiveWindow.View.ShadeEditableRanges = -1 (True) / 0 (False)
ActiveDocument is not always available - WIndowsModification - display shaded / protected areas ??
Creating command buttons from outside the VSTO solution
If you put creating the button "outside" the VSTO solution, then you need to be careful to set the CustomizationContext = this.InnerObject (Me.InnerObject) so that the button is specific to the VSTO document. (By default, Word will probably try to put it in Normal.dot). Pass InnerObject to the method as an argument of the Word.Document variable type.
Word VSTO
With Word, you must consider CustomizationContext (look it up in Word's object model Help). You either add the buttons within the context of a specific document (or the template to which it is attached), or you place them in a globally loaded template. If you don't specify, the Word may put them in one place, then remove them somewhere else, or tell you it exists when, in reality it doesn't in the particular context.
VSTO can be used to customise the behaviour of a particular document or a set of documents created from a common template
Word templates in VSTO behave different to word templates with VBA code
VBA Templates - VBA code in the template and in the document can run concurrently
VSTO Templates - .NET code in the template is associated with the document when it is created. Can you have code associated with the document and more/different code associated with the template linked to that document.
F4 not repeating commands
Style Id = 2321
Autotext Id = 2205
Print Layout instead of Print View
Open Word and display the (Tools > Options)(View tab).
Should the text in brackets be changed to (Print Layout only).
Maximum Number of Undos
There is no option to change the maximum number of undos.
Although in PowerPoint it is possible (Tools > Options)(Edit tab, "Maximum number of undo").
Inconsistent Shortcut Keys
In Excel both these shortcuts close all workbooks and not just the active one.
(Alt + F4) - Closes the active document (saving first) and the exits Word if it is the last document.
(Alt + Shift + F4) - Closes the active document (saving first) and the exits Word if it is the last document.
Ruler cannot be toggled
It is only possible to toggle the display of the ruler from (View > Ruler) when there is an open document
Is there any reason for this ?
The following Properties should be added
The following properties should be added to the Selection object instead of having to use the Range property.
Selection.Range.Bold = False
Selection.Bold = False
Selection.Case
Selection.Duplicate
Selection.GrammarChecked
Selection.GrammaticalErrors
Selection.HighlightColorIndex
Selection.IsEndOfRowMark
Selection.Italic
Selection.ListFormat
Selection.ListParagraphs
Selection.NextStoryRange
Selection.ReadabilityStatistics
Selection.Revisions
Selection.SpellingChecked
Selection.SpellingErrors
Selection.Subdocuments
Selection.SynonymInfo
Selection.TextRetrievalMode
Selection.Underline
The following Methods should be added
Selection.AutoFormat
Selection.CheckGrammar
Selection.CheckSpelling
Selection.CheckSynonyms
Selection.ComputeStatistics
Selection.GetSpellingSuggestions
Selection.InsertAutoText
Selection.InsertDatabase
Selection.LookupNameProperties
Selection.Relocate
Word Normal Changes
If you create "temporary" commands from VBA there is no "changes to Normal" prompt.
However if you create any "temporary" commands from .NET add-ins there is a "changes to normal" prompt.
Normal.dot Exists
In Word 2002 and Word 2003 the Normal.dot is not automatically created when Word is opened as was the case in the previous versions.
In both these versions the Normal.dot may or may not actually exist.
If the Normal.dot template does not exist then the following message will be displayed the first time Word is opened.
Normal.dot Changes
Any changes to the toolbars & menus are automatically stored in the Normal.dot template.
This creates a real problem and the only way round it is to explicitly not save these changes.
To confuse the issue even more the (Tools > COM Add-ins) command needs to be permanently added.
There are two places where you must add additional code:
App_StartUp
Public Sub App_Startup()
'Additional information
If clsTemplate.NormalExists(True) = True Then
If clsTemplate.NormalSavedGet = False Then
If clszMessagesWord.NormalTemplateSaveChangesBeforeQuestion = True Then
Call clsTemplate.NormalSave()
End If
End If
Call App_CmdBarCustomiseMenus()
Call App_CmdBarCustomiseShortcutMenus()
Call App_CmdBarCustomiseToolbars()
Call clsTemplate.NormalSavedSet(True)
End If
End Sub
App_Shutdown
Public Sub App_Shutdown()
'Additional information
If clsTemplate.NormalExists = True Then
If clsTemplate.NormalSavedGet = False Then
'changes have been made while the add-in was installed
Call App_CmdBarResetMenus()
Call App_CmdBarResetShortcutMenus()
Call App_CmdBarResetToolbars()
'therefore automatically save or prompt depending on user's option
Else
Call App_CmdBarResetMenus()
Call App_CmdBarResetShortcutMenus()
Call App_CmdBarResetToolbars()
Call clsTemplate.NormalSavedSet(True)
End If
Else
Call App_CmdBarResetMenus()
Call App_CmdBarResetShortcutMenus()
Call App_CmdBarResetToolbars()
End If
End Sub
Explicit Data Type Conversion
Dim objStyle As Word.Style
objStyle = CType(Application.Selection.Style, Word.Style)
Dim objTemplate As Word.Template
objTemplate = CType(Application.ActiveDocument.AttachedTemplate, Word.Template)
Application.ActiveDocument.SaveAs(Ctype(sfilename, Object))
Range,MoveStart(object, object)
Differences
The following line returns 0 in VBA
objRange.MoveEndWhile(Cset:=Chr(9), Count:=wdBackward)
The following line returns -1 in VSTO
objRange.MoveEndWhile(Cset:=System.Convert.Tochar(9), Count:=Word.wdConstants.wdBackward)
Word.wdColor = RGB( ??
Installing the Add-in
The first time an add-in is installed and loaded the following dialog box will be displayed.
The change that this refers to is the adding of the COM Add-ins command to the Tools drop-down menu.
This command gives you access to all your COM Add-ins and should be permanently added to your Menu Bar.
The toolbar and menu changes that are then made are not saved to your Normal.dot.
If you want to make any manual changes to your toolbars and menus then you should do this before loading the add-in.
Making manual toolbar & menu changes
Select (Tools > COM Add-ins) and unselect any of the Better Solutions add-ins.
Close and exit Word.
Open Word and make your changes to the toolbars and menus.
Select (Tools > COM Add-ins) and select the Better Solutions add-ins.
The above prompt will be displayed again and this will refer to the manual changes you have just made.
Do not make any manual changes to the toolbars and menus while a Better Solutions add-in is installed.
Windows Forms
You are unable to change the order of the windows if you create a new document when you have a windows form displayed
This only happens when the (Tools > Options)(View tab, "Windows in Taskbar") is selected.
Bug - Visual Studio 2008
Word 2007 add-in
error "cannot access a disposed object" - smarttags ??
Document Properties
(It gets information about custom properties) Dim oPropName As Object = typeDocProperties.InvokeMember("Item", Reflection.BindingFlags.Default Or Reflection.BindingFlags.GetProperty, Nothing, objDocumentProperties, New Object() {sPropertyName})
Dim oPropNameType As Type = oPropName.GetType
Dim val As String = oPropNameType.InvokeMember("Value", Reflection.BindingFlags.Default Or Reflection.BindingFlags.GetProperty, Nothing, oPropName, New Object() {}).ToString Return val
a strange error upgraded to Win 7 Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Core.DocumentProperties'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{2DF8D04D-5BFA-101B-BDE5-00AA0044DE52}' failed due to the following error:
No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
It looks like that the method doesn't work in Win 7 anymore BUT just in some specific condition (It seems it has problem when a document is being opened, otherwise it's to be working fine)
I changed the code to use 'normal' approach and it seems to be working fine.
Dim properties As Microsoft.Office.Core.DocumentProperties
properties = CType(objDocument.CustomDocumentProperties, Office.DocumentProperties)
Dim prop = properties.Cast(Of Office.DocumentProperty)().FirstOrDefault(Function(x) x.Name.ToLower.Equals(sPropertyName.ToLower))
If prop Is Nothing Then Return String.Empty Return prop.Value
Public Class CustomDocProperties
' Note: Object type is used instead of Office.DocumentProperties to avoid a type conversion error
Private CustomDocProps As Object
' DocProperty code using Object
Private ReadOnly Property DocProperty(ByVal Name As String) As Object
<DebuggerStepThrough()> _
Get
Try
' Note: This is significantly faster than looping through the properties
Return CustomDocProps(Name.ToString)
Catch ex As Exception
Return Nothing
End Try
End Get
End Property
Property Value(ByVal Name As EraCustomPropertyName) As Object
Get
Dim docProp As Object = DocProperty(Name)
If docProp IsNot Nothing Then
Return docProp.Value
Else
Return Nothing
End If
End Get
Set(ByVal value As Object)
Dim docProp As Object = DocProperty(Name)
If docProp IsNot Nothing Then
docProp.Value = value ' set value
Else
Add(Name, value) ' add new prop and set value
End If
End Set
End Property
Private Function Add(ByVal Name As String, ByVal Value As Object) As Object
If TypeOf Value Is Integer OrElse TypeOf Value Is Double Then
' Numeric
Return CustomDocProps.Add(Name.ToString, False, Core.MsoDocProperties.msoPropertyTypeNumber, Value)
Else
' String
Return CustomDocProps.Add(Name.ToString, False, Core.MsoDocProperties.msoPropertyTypeString, Value)
End If
End Function
Sub Delete(Name As String)
Dim docProp As Object = DocProperty(Name)
If docProp IsNot Nothing Then
docProp.delete()
End If
End Sub
Public Sub New(ByVal WordDoc As Word.Document, Optional ByVal TemplateProperty As Boolean = False)
If TemplateProperty Then
CustomDocProps = WordDoc.AttachedTemplate.CustomDocumentProperties
Else
CustomDocProps = WordDoc.CustomDocumentProperties
End If
End Sub
End Class
Declaring Events
You need to use the ApplicationEvents4_Event interface and the DocumentEvents2_Event interface
When you want to define an event using the Application or Document objects.
This casting must be done when you declare any events, not just ones that have a conflicting method and event name
Application.DocumentBeforeClose
app.DocumentBeforeClose += new Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(App_DocumentBeforeClose);
Application.Quit
Call CType(gApplication, Word._Application).Quit()
Application.NewDocument
public void Event_ApplicationNewDocument
{
}
((Word.ApplicationEvents4_Event)application).NewDocument += new Word.ApplicationEvents4_NewDocumentEventHandler(Event_ApplicationNewDocument);
Document.Close
public void Event_DocumentClose
{
}
((Word.DocumentEvents2_Event)doc).Close += new Word.DocumentEvents2_CloseEventHandler(Event_DocumentClose)
CustomizationContext
Returns or sets a Template or Document object that represents the template or document in which changes to menu bars, toolbars and key bindings are stored.
This corresponds to the value of the "Save in" box on the (Tools > Customize)(Commands tab)
When customisations are saved in a particular template or document, they are only available when this document, a document based on the template or if its a global template when this template is loaded.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext