Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.Net VSTO Automation Issue

Status
Not open for further replies.

JasonEnsor

Programmer
Sep 14, 2010
193
GB
Hi Guys,

I am pretty new to VSTO and VB (Although I have done VBA), I am trying to automate inserting custom document properties in to a word document that is generated from excel. I can update built in properties but the custom properties throws an error if I remove the If Statement, if I leave the If statement in the property isn't created.

I am using Visual Studio 2010 and Office 2010

Code:
Imports Microsoft.Office.Interop

Public Class ThisAddIn

    Dim oWord As Microsoft.Office.Interop.Word.Application
    Dim oDoc As Microsoft.Office.Interop.Word.Document
    '  Dim oCustomProps As Microsoft.Office.Interop.Word.CustomProperties

    Private Sub ThisAddIn_Startup() Handles Me.Startup
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add

        Dim _BuiltInProperties As Object = oDoc.BuiltInDocumentProperties
        Dim oCustomProps As Object = oDoc.CustomDocumentProperties

        If oCustomProps Is Nothing Then
            oCustomProps.Add("Custom", "Whoop")
        End If

        If Not _BuiltInProperties Is Nothing Then

            _BuiltInProperties("Title").Value = "Testing"

        End If

    End Sub


    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

End Class

Any Help would be appreciated

J.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top