Programmatically Docking a Notebook in OneNote 2010
Handy Programming Tips for Microsoft OneNote 2010: Learn how to programmatically dock or undock a Microsoft OneNote 2010 notebook.
Last modified: July 29, 2011
Applies to: Excel 2010 | Office 2010 | OneNote 2010 | VBA
Published: August 2011
Provided by: Frank Rice, Microsoft Corporation
Microsoft OneNote 2010 enables you to take and organize notes, include images and web pages, record audio, share your notes with others, and generally keep information from the many parts of your life organized within one simple application. In this topic, you use the Window object to dock or undock a notebook from the right-side of the desktop. To complete this task, you must do the following:
To use the code in this topic, you need to run it from a Microsoft Office 2010 host program. These include Microsoft Excel 2010, Microsoft PowerPoint 2010, and Microsoft Word 2010. However, OneNote 2010 is not considered a host program. Excel is used in this topic.
To add references to the workbook
Start Excel 2010.
On the Developer tab, click Visual Basic. This opens the Visual Basic Editor.
If you do not see the Developer tab in Excel, click the File tab, and then click Options. In the categories pane, click Customize Ribbon, select Developer, and then click OK.
On the Tools menu, click References.
Scroll to Microsoft OneNote 14.0 Object Library, and then select it.
Next, scroll to Microsoft XML, 6.0, select it, and then click OK.
In this task, you add programming code to the Visual Basic Editor.
To add code to the Visual Basic Editor
In the Projects pane, click Module1.
Paste or type the following Microsoft Visual Basic for Applications (VBA) code into the module window.
Before running the code, you need to open a OneNote 2010 notebook.
Public Sub DockOneNoteWindow() ' Connect to OneNote 2010. Dim oneNote As OneNote14.Application Set oneNote = New OneNote14.Application If oneNote.Windows.CurrentWindow Is Nothing Then MsgBox "There isn't a visible OneNote 2010 window. Please start OneNote." Else ' Get the Current Window Dim oneNoteWindow As OneNote14.Window Set oneNoteWindow = oneNote.Windows.CurrentWindow ' If the current Window isn't a SideNote window, ' dock to the right of the screen if it's ' not currently docked. ' Otherwise, undock the Window. If Not oneNoteWindow.SideNote Then If oneNoteWindow.DockedLocation = dlNone Then oneNoteWindow.DockedLocation = dlRight Else oneNoteWindow.DockedLocation = dlNone End If Else MsgBox "The current OneNote window is a SideNote." End If End If End Sub
The DockOneNoteWindow procedure uses the OneNote 2010Window object to dock the notebook to the right-side of the desktop, if it is not already docked. Otherwise, the notebook is undocked.