Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hello


    when I run the below code the error message displays "Object reference not set to an instance of an object"

    its on the line
    With wordList.Application.ListGalleries(WdListGalleryTy pe.wdBulletGallery).ListTemplates(1).ListLevels(1)


    I understand that I must set this line to something eg a selection.

    However Im unsure on how to do this.


    Previously when I defined

    'Dim Word As Microsoft.Office.Interop.Word.Application

    This worked, however what was occuring in the background a new instance of Winword.exe was being created and didn not close.

    Can a second set of eyes pls look at my code and let me know what/where Im going wrong.

    many thanks

    diana


    Code:
    Public Sub OnActionCorrsWordApplyStyle(ByVal control As IRibbonControl)
            Try
                Dim wordDoc As WordDocument = WordLibrary.ActiveDocument
                Dim selectionStyle As MSWord.Style = CType(wordDoc.Library.Application.Application.Selection.Style, Microsoft.Office.Interop.Word.Style)
                Dim style2 As MSWord.Style = wordDoc.GetStyle("Normal")
    
                Dim wordList As Microsoft.Office.Interop.Word.ListGalleries
    
    
                'Dim Word As Microsoft.Office.Interop.Word.Application
    
                'Dim WordApp As Microsoft.Office.Interop.Word.Application
    
                'Dim wordList As MSWord.ListGalleries
                
                'Dim selection As MSWord.Selection = wordDoc.Document.Application.Selection
    
    
                Dim selection As MSWord.Selection = wordDoc.Library.Application.Selection
    
    
    
                If control.Tag = "Corrs Bullet" Or control.Tag = "Corrs Number" Then
    
                   
    
    
                    With wordList.Application.ListGalleries(WdListGalleryType.wdBulletGallery).ListTemplates(1).ListLevels(1)
    
                        .NumberFormat = ChrW(61623)
                        .ResetOnHigher = CInt(False)
                        .StartAt = 1
                        .LinkedStyle = ""
                        .TrailingCharacter = WdTrailingCharacter.wdTrailingTab
                        .NumberStyle = WdListNumberStyle.wdListNumberStyleBullet
                        .Alignment = WdListLevelAlignment.wdListLevelAlignLeft
                        .TextPosition = wordList.Application.CentimetersToPoints(1.5)
                        .TabPosition = wordList.Application.CentimetersToPoints(1.5)
                        With .Font
                            .Name = "Symbol"
                        End With
    
                    End With
                    wordList.Application.ListGalleries(WdListGalleryType.wdBulletGallery).ListTemplates(1).Name = ""
    
    
                    'reset on higher to false so each time
                    'Corrs numbering doesnt restart everytime its inserted
                    With wordList.Application.ListGalleries(WdListGalleryType.wdNumberGallery).ListTemplates(1).ListLevels(1)
                        .NumberFormat = "%1"
                        .TrailingCharacter = WdTrailingCharacter.wdTrailingTab
                        .NumberStyle = WdListNumberStyle.wdListNumberStyleArabic
                        .NumberPosition = wordList.Application.CentimetersToPoints(0)
                        .Alignment = WdListLevelAlignment.wdListLevelAlignLeft
                        .TextPosition = wordList.Application.CentimetersToPoints(1.5)
                        .TabPosition = wordList.Application.CentimetersToPoints(1.5)
                        .ResetOnHigher = CInt(False)
                        .StartAt = 1
    
                        'ensure number is not bold
                        With .Font
                            .Bold = CInt(False)
                        End With
                    End With
                    wordList.Application.ListGalleries(WdListGalleryType.wdNumberGallery).ListTemplates(1).Name = ""
    
    
    
                    With selection
                        .ParagraphFormat.LeftIndent = 0
                        .ParagraphFormat.TabIndent(CShort(1.5))
                    End With
    
    
     
    
                    If control.Tag = "Corrs Bullet" Then
    
                        If selectionStyle.NameLocal = "Corrs Bullet" Then
                            wordDoc.Document.Application.Selection.Style = style2
                            Exit Sub
    
                        Else
    
                            If selection.Application.Selection.Range.ListFormat.ListType = 0 Then
    
                                If selectionStyle.NameLocal = "Normal Indent" Then
                                    wordDoc.Document.Application.Selection.Style = "Normal"
                                End If
                                selection.Application.ListGalleries(WdListGalleryType.wdBulletGallery).ListTemplates(1).Name = ""
    
                            Else
                                selection.Application.Application.Selection.Range.ListFormat.RemoveNumbers()
    
                            End If
                            Exit Sub
    
                        End If
    
                    End If
    
    
                    If control.Tag = "Corrs Number" Then
    
                        If selectionStyle.NameLocal = "Corrs Number" Then
                            wordDoc.Document.Application.Selection.Style = style2
                            Exit Sub
    
                        Else
    
                            If selection.Application.Selection.Range.ListFormat.ListType = 0 Then
    
                                If selectionStyle.NameLocal = "Normal Indent" Then
                                    wordDoc.Document.Application.Selection.Style = "Normal"
                                End If
                                selection.Application.ListGalleries(WdListGalleryType.wdNumberGallery).ListTemplates(1).Name = ""
    
                            Else
                                selection.Application.Selection.Range.ListFormat.RemoveNumbers()
    
                            End If
                            Exit Sub
    
                        End If
    
                    End If
                End If
    
    
                Init()
    
                Dim style As MSWord.Style = WordLibrary.ActiveDocument.GetStyleNoError(control.Tag)
                If style Is Nothing Then
                    WordLibrary.Application.OrganizerCopy(Source:= _
            "C:\Program Files\CorrsOffice\Templates\Document.dotx", Destination:= _
            WordLibrary.Application.ActiveDocument.FullName, Name:=control.Tag, Object:=Microsoft.Office.Interop.Word.WdOrganizerObject.wdOrganizerObjectStyles)
                    style = WordLibrary.ActiveDocument.GetStyle(control.Tag)
    
                End If
                If style IsNot Nothing Then m_documentstyleController.SetFontStyle(WordLibrary.ActiveDocument, style)
            Catch ex As Exception
                Logger.Message(ex.Message)
            End Try
        End Sub

  2. #2
    New Lounger
    Join Date
    Apr 2010
    Location
    Naperville, IL
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Diana.

    It may be something as simple as doing a "Dim wordlist as New Microsoft.Office.Interop.Word.ListGalleries". Try using "New" as my experience with Office objects is that simply dimming them isn't enough.

    Hope that helps!

    Jeff
    My name is Jeff Penchoff and I'm a computer programmer by profession.

    My LLC is Web Success Partners where I market various products and work with a large community of website owners. Stop by and check us out!

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks Jeff

    yes i have to read up on defining in vb.net

    many thanks again Jeff

    diana

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The Set keyword is not supported under VB .NET, nor is the companion Let keyword So, the .NET syntax looks like like Jeff says.

    From VB .NET Language in a Nutshell: Appendix A: What's New and Different in VB .NET

    Object Creation
    VB 6 supports a form of object creation called implicit object creation. If an object variable is declared using the New keyword:

    Dim obj As New SomeClass

    then the object is created the first time it is used in code. More specifically, the object variable is initially given the value Nothing, and then every time the variable is encountered during code execution, VB checks to see if the variable is Nothing. If so, the object is created at that time.

    VB .NET does not support implicit object creation. If an object variable contains Nothing when it is encountered, it is left unchanged, and no object is created.

    In VB .NET, we can create an object in the same statement as the object-variable declaration, as the following code shows:

    Dim obj As SomeClass = New SomeClass

    As a shorthand, we can also write:

    Dim obj As New SomeClass

    If the object's class constructor takes parameters, then they can be included, as in the following example:

    Dim obj As SomeClass = New SomeClass(argument1, argument2,...)

    As a shorthand, we can also write:

    Dim obj As New SomeClass(argument1, argument2,...)

    --
    Alan

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts
    many thanks Alan

    At lunch time Im heading out to the bookstore to buy that book

    thanks again Alan

    diana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •