I just posted an interview with Kris Makey on Channel9. Kris is a Developer on the Office Client team. Here he shows us a couple new features of Office projects in Visual Studio 2008 SP1. First he demonstrates a new error logging feature that will log any end-user install errors to the Event Log making it much easier to tell what went wrong. He also shows us how you can place Winforms controls directly on document surfaces.
For more information on Office Development with Visual Studio visit the developer portal at http://msdn.com/vsto.
Enjoy,-Beth Massi, Visual Studio Community
With the release of Visual Studio 2008 SP1, you can now add smart tags to Excel by using an add-in. In this video, I show you how to add them to both a document-level customization and an add-in project.
How Do I: Add Smart Tags to Excel Workbooks?
This video is based on the topic: How to: Add Smart Tags to Excel Workbooks, where you can get the code and follow along step-by-step.
It doesn't take much code to add a command to a shortcut menu in Excel, but the menu objects have strange names so it's not intuitive, to me at least. The trickiest part is just sorting out how it's supposed to work, because it seems like it should be different from adding buttons to toolbars, but it really looks like that's what you're doing.
You can watch the video and make me happy, or you can just jump to the code example that's all given a little lower down. Thanks to McLean Schofield, programmer/writer and 3-star forum answer person, for this code example!
Duration: 3 minutes, 50 seconds.
Public Class ThisAddIn
Private WithEvents writeToText As Office.CommandBarButton Private selectedCells As Excel.Range
Private Sub ThisAddIn_Startup(ByVal sender _ As Object, ByVal e As System.EventArgs) Handles Me.Startup
DefineShortcutMenu() End Sub
Private Sub DefineShortcutMenu()
Dim menuItem As Office.MsoControlType = Office.MsoControlType.msoControlButton writeToText = Application.CommandBars("Cell").Controls.Add(Type:=menuItem, _ Before:=1, Temporary:=True)
writeToText.Style = Office.MsoButtonStyle.msoButtonCaption writeToText.Caption = "Write to a Text File" writeToText.Tag = "0" End Sub
Private Sub Application_SheetBeforeRightClick(ByVal Sh _ As Object, ByVal Target As Microsoft.Office.Interop.Excel.Range, _ ByRef Cancel As Boolean) Handles Application.SheetBeforeRightClick
selectedCells = Target End Sub
Private Sub writeToText_Click(ByVal Ctrl As Office.CommandBarButton, _ ByRef CancelDefault As Boolean) Handles writeToText.Click
Try Dim currentDateTime As System.DateTime = _ System.DateTime.Now Dim dateStamp As String = _ currentDateTime.ToString("dMMMMyyyy_hh.mm.ss")
Dim fileName As String = System.Environment.GetFolderPath( _ Environment.SpecialFolder.MyDocuments) & "\\" & _ dateStamp & ".txt" Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(fileName)
For Each cell As Excel.Range In selectedCells.Cells If cell.Value2 IsNot Nothing Then sw.WriteLine(cell.Value2.ToString()) End If Next sw.Close() Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try
End Sub
End Class
Now what do I do? I'd like to help you navigate the information we published about SP1. I strongly recommend that you read the VSTO section of the SP1 Readme here. You can read about all the great improvements to Visual Studio in the Knowledge Base article about all the bug fixes we put into the Service Pack. Hopefully your issues were addressed in this SP.
If you want to know how my team decided what to put into the Service Pack, you can read the archived blog entry from June titled "What's New in VS 2008 SP1 and how the VSTO team decided what to include in a Service Pack."
For an overview of What's New in Visual Studio Tools for Office with SP1, you can read the linked article in the documentation. The documentation is Localized, so you can read it in Japanese, German, or any of the other languages that our documentation supports!
What's New in Visual Studio Tools for Office Visual Studio 2008 Service Pack 1 (SP1) contains updates and new features that affect Visual Studio Tools for Office. The SP1 changes are listed separately from the Visual Studio 2008 features to help you find the latest additions quickly. Visual Studio 2008 SP1 includes features that are designed to help you accomplish the following tasks: Add Host Controls and Smart Tags to Add-in Projects You can add smart tags and host controls, such as content controls in Word 2007 and list objects in Excel 2007, to documents in application-level add-in projects. These managed host controls behave like native Office objects, but with added functionality such as events and data-binding capabilities. To get started, see Adding Controls to Office Documents at Run Time and Smart Tags Overview. Deploy the Office Primary Interop Assemblies with Your Solution Installer When you use ClickOnce to deploy solutions for the 2007 Microsoft Office system, the Microsoft Office 2007 Primary Interop Assemblies are automatically selected as prerequisites. The primary interop assemblies are copied to the same deployment folder as your solution installer. To get started, see How to: Install Prerequisites on End User Computers to Run Office Solutions (2007 System). Rapidly Deploy Your Solution with the .NET Framework Client Profile You can now specify the .NET Framework Client Profile as the target Framework version. This smaller version of the .NET Framework decreases the size of your solution during installation by not including all of the Framework assemblies. You can use this with your solutions for the 2007 Microsoft Office system. To get started, see Creating Office Solutions in Visual Studio. Troubleshoot Installation with the Event Viewer · When you install or uninstall Visual Studio Tools for Office solutions, the Visual Studio Tools for Office runtime logs error messages that you can view by using the event viewer in Windows. You can use these messages to help resolve installation and deployment problems. To get started, see Event Logging (2007 System).
Visual Studio 2008 Service Pack 1 (SP1) contains updates and new features that affect Visual Studio Tools for Office. The SP1 changes are listed separately from the Visual Studio 2008 features to help you find the latest additions quickly. Visual Studio 2008 SP1 includes features that are designed to help you accomplish the following tasks:
You can add smart tags and host controls, such as content controls in Word 2007 and list objects in Excel 2007, to documents in application-level add-in projects. These managed host controls behave like native Office objects, but with added functionality such as events and data-binding capabilities.
To get started, see Adding Controls to Office Documents at Run Time and Smart Tags Overview.
When you use ClickOnce to deploy solutions for the 2007 Microsoft Office system, the Microsoft Office 2007 Primary Interop Assemblies are automatically selected as prerequisites. The primary interop assemblies are copied to the same deployment folder as your solution installer.
To get started, see How to: Install Prerequisites on End User Computers to Run Office Solutions (2007 System).
You can now specify the .NET Framework Client Profile as the target Framework version. This smaller version of the .NET Framework decreases the size of your solution during installation by not including all of the Framework assemblies. You can use this with your solutions for the 2007 Microsoft Office system.
To get started, see Creating Office Solutions in Visual Studio.
· When you install or uninstall Visual Studio Tools for Office solutions, the Visual Studio Tools for Office runtime logs error messages that you can view by using the event viewer in Windows. You can use these messages to help resolve installation and deployment problems.
To get started, see Event Logging (2007 System).
A lot of people would like to do this. It makes sense that a developer would want to select the custom tab automatically, if the controls that are most useful for the current document are all on that tab. This video goes in-depth about this programming question.
OK, not really. The video just says you can't do it, because the Ribbon is designed with the idea of leaving the user in control of the UI -- no surprise selection changes. But you should watch the video anyway. It's really short, and, you know, kinda funny.
Related resources
Forum: Is there a way to activate a certain tab on the Ribbon?
Duration: 1 minute, 8 seconds