Hi,

I'm writing a function that takes a word doc and returns the number of pages in it. I have the function working and returning pages except that it opens a Word dialog asking if I want to save changes - does anyone know how to stop this? I have the document running "silently" in the background so I don't want to spoil the feel by prompting for saves.
Here is my code:

Private Function CountWordPages(ByRef Doc As String) As Integer
        Dim oWord As Object
        Dim WD_Doc As Word.Document
        Dim intCount As Integer = 0
        On Error GoTo ErrorHandler
        oWord = CreateObject("Word.Application") 'late bind for differing versions of word
        WD_Doc = oWord.Documents.Open(Doc, True, True, False, , , , , , , , False) 'open silently in background
        intCount = WD_Doc.ComputeStatistics(Word.WdStatistic.wdStatisticPages) 'get count
        WD_Doc = Nothing 'done with the doc
        oWord.Application.Quit() ' close the app
        oWord = Nothing 'tidy up
        CountWordPages = intCount 'return count
        Exit Function
ErrorHandler:
        DisplayError(Err.Number, Err.Description)
    End Function

Thanks in advance

Hi All,

I managed to figure it out, I should have closed with:

oWord.Application.Quit(False)

Thanks for the info on how you fixed it. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.