Results 1 to 18 of 18

Thread: CreateObject("Word.Application") very slow with Word version 16

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    CreateObject("Word.Application") very slow with Word version 16

    It takes exactly 3 seconds at that line in a computer with an I5 processor at 3.89 GHz.

    Could be that considered normal?
    That line used to take negligible time with older Office versions and in much slower computers.

    That causes a problem in the usability of some screens where I offer to edit Word files, because the user clicks to edit a document and nothing happens for several seconds.
    Then, if the user closes that document and opens a new one, again she/he needs to wait several seconds while nothing happens.

    I'm thinking to keep the Word object instantiation opened (to speed up at least the second and further editions), but before I go that route I wanted to consult with you, if you know something about this issue.
    Thanks.

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: CreateObject("Word.Application") very slow with Word version 16

    Do you absolutely have to use late binding? Switching to early binding should speed it up considerably.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: CreateObject("Word.Application") very slow with Word version 16

    Quote Originally Posted by fafalone View Post
    Do you absolutely have to use late binding? Switching to early binding should speed it up considerably.
    I suppose that yes... I target any version of Word that could be installed from 2003 to 16.

    I never worked with early binding for Office.
    What would happen if I reference Word 2003?

    And what happens if there is no Word installed on the machine.
    I think the program can't even enter to that form. (I'm asking because I don't remember)

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: CreateObject("Word.Application") very slow with Word version 16

    What would happen if I reference Word 2003?
    any reference to an uninstalled version of word will result in missing reference, even if the reference is not used, this will cause problems throughout the code

    i would have to give consideration to creating the word application object in background, just in case the user wanted it at some point, just make sure to close with program

    if the user could already have word open, you could use the existing instance of word, rather than creating an additional instance, but you would need to make sure to leave in the same state on closing
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: CreateObject("Word.Application") very slow with Word version 16

    Quote Originally Posted by westconn1 View Post
    any reference to an uninstalled version of word will result in missing reference, even if the reference is not used, this will cause problems throughout the code

    i would have to give consideration to creating the word application object in background, just in case the user wanted it at some point, just make sure to close with program

    if the user could already have word open, you could use the existing instance of word, rather than creating an additional instance, but you would need to make sure to leave in the same state on closing
    Thank you.

    I have some utilities in the program that use Word but are not always used, only sometimes.
    My idea now is to start the instance of Word the first time it is needed and leave it open until the user closes that screen.

    I can't believe that it was something that used to take just milliseconds in Office versions 15 years old and machines also 15 years old and now with a machine that is 100 timer faster it takes three seconds.
    These people must hate that their products are used.

  6. #6
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: CreateObject("Word.Application") very slow with Word version 16

    Quote Originally Posted by Eduardo- View Post
    I suppose that yes... I target any version of Word that could be installed from 2003 to 16.

    I never worked with early binding for Office.
    What would happen if I reference Word 2003?

    And what happens if there is no Word installed on the machine.
    I think the program can't even enter to that form. (I'm asking because I don't remember)
    When you use early binding, the newer version will be automatically loaded. You'd reference the earliest version you support; if you add a reference to e.g. Word 8.0 Object Library, then run on a machine with 9.0, the Word 9.0 Object Library would be loaded.
    If Word wasn't installed at all you'd get a local error, probably 'can't create object' on Set = New; you'd trap it like any other and handle the same way as when CreateObject fails.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: CreateObject("Word.Application") very slow with Word version 16

    Quote Originally Posted by fafalone View Post
    If Word wasn't installed at all you'd get a local error, probably 'can't create object' on Set = New; you'd trap it like any other and handle the same way as when CreateObject fails.
    Humm, but that's not what happens with other missing references.
    I think you get the error as soon as you enter the procedure, or the form (or the module), depending on the scope of the variable that is referencing it.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: CreateObject("Word.Application") very slow with Word version 16

    Other problem of switching to early binding is that I'll need Word 2003 installed in any machine where I'll work in development of this program.

    Currently I can work on any machine as soon as I install VB6.

  9. #9
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: CreateObject("Word.Application") very slow with Word version 16

    I don't think the problem is early/late binding. Some other possibilities could be slow addins, a problem with the normal template, hardware, or just a faulty office install. I never thought the last was an issue, but after working in a large company for a while I can say that it does happen.

    Since one of your concerns is the user experience, you could open something that indicates that word is starting up in the background. When it gets hung there, the user will know what's going on and put the blame where it's due.

  10. #10
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: CreateObject("Word.Application") very slow with Word version 16

    err yeah nevermind I was thinking of something else with the errors; you'd get user-defined type not defined and not be able to compile.


    I don't think you'd need a full blown install of 2003 though just the referenced file.

    It's do-able, just a question of how much effort those seconds are worth. Maybe someone smarter than me will pop in with another way to speed it up.

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: CreateObject("Word.Application") very slow with Word version 16

    one possible delay is that so many of these programs now connect to the internet (if possible) to validate when opening
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: CreateObject("Word.Application") very slow with Word version 16

    Quote Originally Posted by dmaruca View Post
    I don't think the problem is early/late binding. Some other possibilities could be slow addins, a problem with the normal template, hardware, or just a faulty office install. I never thought the last was an issue, but after working in a large company for a while I can say that it does happen.
    If anyone else has Word 16 and could test:

    Code:
    Private Sub Form_Load()
        Dim t
        Dim w As Object
        
        t = Timer
        Set w = CreateObject("Word.Application")
        MsgBox Int((Timer - t) * 1000) / 1000
    End Sub
    Quote Originally Posted by dmaruca View Post
    Since one of your concerns is the user experience, you could open something that indicates that word is starting up in the background. When it gets hung there, the user will know what's going on and put the blame where it's due.
    Or I could put a message "next version will work with Open Office".

    Quote Originally Posted by westconn1 View Post
    one possible delay is that so many of these programs now connect to the internet (if possible) to validate when opening
    But every time? Still, I think it would be usually faster than three seconds.
    I have installed a program (Glasswire) that notifies when programs connect to intenet, but it doesn't tell anything when the Word instance is created.

  13. #13
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: CreateObject("Word.Application") very slow with Word version 16

    Code:
    Private Sub Form_Load()
        Dim t
        Dim w As Object
        
        t = Timer
        Set w = CreateObject("Word.Application")
        MsgBox Int((Timer - t) * 1000) / 1000
    End Sub
    Took 1.7 seconds on my machine (running from an SSD)

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: CreateObject("Word.Application") very slow with Word version 16

    Quote Originally Posted by Arnoutdv View Post
    Code:
    Private Sub Form_Load()
        Dim t
        Dim w As Object
        
        t = Timer
        Set w = CreateObject("Word.Application")
        MsgBox Int((Timer - t) * 1000) / 1000
    End Sub
    Took 1.7 seconds on my machine (running from an SSD)
    Thank you. The difference can be considered big, because it is almost half the time. I'm also with a SSD.
    Still, 1.7 seconds seems too much.

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: CreateObject("Word.Application") very slow with Word version 16

    I tested keeping the Word instance opened but the issue is that the user can close it, when the user closes a document in fact she/he closes the Word window and the instance is terminated, and when I try to reuse it opening a new document I get an error.

    Another thing that takes several seconds is when I set the Document object reference to Nothing (at the end).

  16. #16
    Registered User
    Join Date
    Sep 2022
    Posts
    1

    Post Re: CreateObject("Word.Application") very slow with Word version 16

    Quote Originally Posted by Eduardo- View Post
    I tested keeping the Word instance opened but the issue is that the user can close it, when the user closes a document in fact she/he closes the Word window and the instance is terminated, and when I try to reuse it opening a new document I get an error.

    Another thing that takes several seconds is when I set the Document object reference to Nothing (at the end).
    I am also getting the same issue causing considerable problem to the user. Whether your issue is resolved ? If yes, what was the solution. I tried to kill the WINWORD.EXE using TerminateProcess and then setting word object to Nothing, it still getting delayed.

    Any advise will be greatly received

    Thanks
    Sadagopan TS

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: CreateObject("Word.Application") very slow with Word version 16

    Quote Originally Posted by Sadagopan TS View Post
    I am also getting the same issue causing considerable problem to the user. Whether your issue is resolved ? If yes, what was the solution. I tried to kill the WINWORD.EXE using TerminateProcess and then setting word object to Nothing, it still getting delayed.

    Any advise will be greatly received

    Thanks
    Sadagopan TS
    No... The only workaround is not to start a new instance every time and try to reuse the same for several tasks, when you need to do several consecutive tasks.

    I takes several seconds to start.

  18. #18
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: CreateObject("Word.Application") very slow with Word version 16

    I use word and I noticed that the only thing that is fast enough is CheckSpelling.
    trying to add grammar will make everything too slow.
    also I use it in my "graphical" text-editor for my game. so its not any textbox or any string.
    what I do is that I analyze "new/changed" words, so its not continuous check and not the whole text.
    also, it will only work during idle. when user is typing the checking is paused. (like 1 second, but its good enough to not create too many calls)

    first I initialize it
    Set wd = CreateObject("Word.Application")
    wd.Options.IgnoreMixedDigits = False
    wd.Options.IgnoreUppercase = False

    and after that I just call
    wd.CheckSpelling(wordtocheck$)
    for each word I want checked.

Posting Permissions

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



Click Here to Expand Forum to Full Width