Results 1 to 25 of 25

Thread: [RESOLVED] Why does this work only once

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Resolved [RESOLVED] Why does this work only once

    The following code copies whatever text is selected then adds it to a newly-created Word doc, removes numbering (as in bullet numbering) and then replaces what is on the clipboard with the modified text. It works fine when Word isn't already open. However if Word is already open it works fine the first time but after that the content of the clipboard isn't changed. Can anybody tell me why?

    vb Code:
    1. SendKeys "^c", True
    2.    
    3.     With wdApp
    4.         .Documents.Add , , wdNewBlankDocument, True
    5.         .Documents(1).Activate
    6.         DoEvents
    7.    
    8.         .Selection.PasteAndFormat wdPasteDefault
    9.         .Selection.WholeStory
    10.         .Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
    11.         .Selection.Copy
    12.  
    13.         .Documents(1).Close SaveChanges:=wdDoNotSaveChanges
    14.  
    15.         If .Documents.Count = 0 Then
    16.             .Quit
    17.             Set wdApp = Nothing
    18.         End If

  2. #2
    Member
    Join Date
    Feb 2007
    Posts
    39

    Re: Why does this work only once

    Not an expert so if im wrong just tell me and ill delete it

    I think if you clear the clipboard in your code it will work

    like...

    as soon as the text copies an event clears the clipboard and starts over

    Just a thought

  3. #3

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why does this work only once

    Quote Originally Posted by blckoutdfndr
    Not an expert so if im wrong just tell me and ill delete it

    I think if you clear the clipboard in your code it will work

    like...

    as soon as the text copies an event clears the clipboard and starts over

    Just a thought
    Why then does it work when Word isn't open?

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Why does this work only once

    That's a possibility, as you often need to have "Clipboard.Clear" when using VB's clipboard functions, but I suspect it isn't the issue here..

    One problem is that you are referencing the document by position, and if any others were already open this position will not be correct. I think you also need to Select the document (or perhaps a range in it) in addition to Activating it.

    Untested, but I think this will be better:
    vb Code:
    1. SendKeys "^c", True
    2.  
    3. Dim wdDoc as Word.Document 'or "as Object" for late bound
    4.          
    5.           With wdApp
    6.               Set wdDoc = .Documents.Add (, , wdNewBlankDocument, True)
    7.               wdDoc.Activate
    8.               wdDoc.Select
    9.               DoEvents
    10.               .Selection.PasteAndFormat wdPasteDefault
    11.               .Selection.WholeStory
    12.               .Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
    13.               .Selection.Copy
    14.  
    15.               wdDoc.Close SaveChanges:=wdDoNotSaveChanges
    16.               Set wdDoc = Nothing
    17.  
    18.               If .Documents.Count = 0 Then
    19.                   .Quit
    20.                   Set wdApp = Nothing
    21.               End If
    Thank, I'll try that but I checked and Word always (at least the way I'm using it) seems to add the new doc as Documents(1).
    Last edited by MartinLiss; Mar 18th, 2007 at 02:25 PM.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why does this work only once

    I would say that since you are hardcoding in a document index number instead of a name or using a document object variable, it is pasting the text into the first document and not the added document.

    I will test out your code and see if I can figure it out...


    Edit: lol, all the points I was going to make in the utility thread.

    Martin, you can compare my spellchecker code to what you are using too to see the differences.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Why does this work only once

    I don't think the problem has anything to do with your code as such - If you stick Debug.Print Clipboard.GetData after the SendKeys line you'll see that the text just isn't being copied. When word (or any office app) is open the office clipboard takes over, and perhaps the extra layer (whatever office does) increases the chance of (the already flaky) SendKeys falling over. When I was trying out your code I found the behaviour to be sporadic.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why does this work only once

    Here is my spellchecker code to eitehr start a new or attach to an existing word app object:
    vb Code:
    1. Public Sub InitializeMe()
    2.     On Error Resume Next
    3.     '<INITIALIZE WORD>
    4.     Set moApp = GetObject(, "Word.Application")
    5.     If TypeName(moApp) <> "Nothing" Then
    6.         Set moApp = GetObject(, "Word.Application")
    7.     Else
    8.         Set moApp = CreateObject("Word.Application")
    9.     End If
    10. End Sub
    And to use a sure fire way of copying the correct document data using the range.copy instead... (setting your added doc to a document object variable)
    vb Code:
    1. Clipboard.Clear
    2. oDoc.Select
    3. 'Do your bullet removal stuff
    4. oDoc.Range.Copy
    5. sReplace = Clipboard.GetText(1)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why does this work only once

    Si, I see I edited your post above instead of replying to it Sorry about that but in any case I just tried your modification and there's no change. With Word open it works only once.

  9. #9

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why does this work only once

    Rob as far as opening Word I'm doing the following which I believe works just as well.
    vb Code:
    1. hwnd = FindWindow("OpusApp", vbNullString)
    2.     If hwnd = 0 Then
    3.         Set wdApp = New Word.Application
    4.     Else
    5.         Set wdApp = Word.Application
    6.     End If

    I'll try your other change however.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why does this work only once

    Yes it does but its also using early binding which may create issues when other members try it as the reference will be broken.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why does this work only once

    Thanks. I'll change that.

    The problem may be due to the way Word (or I) handles the clipborad because after adding ClipBoard.Clear I get a Word error 4605 "This method or property is not available because the clipboard is empty or not valid".

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why does this work only once

    First attempt when word is alread running with one document in it...

    Prompts to close/save document1.
    Quits Word.

    Seems its always closing word if its already open. Looks like it needs a boolean flag to prevent it from getting quit when already was running.


    More testing...
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why does this work only once

    Quote Originally Posted by RobDog888
    First attempt when word is alread running with one document in it...

    Prompts to close/save document1.
    Quits Word.

    Seems its always closing word if its already open. Looks like it needs a boolean flag to prevent it from getting quit when already was running.


    More testing...
    It doesn't do that when I run it.

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why does this work only once

    Well I simulated a user typing in a document1 without it being saved. Then ran the app and alt+c etc and got the document1 closing and re-adding a new one for pasting.

    Looks like I may have fixed the issues. I added a boolean for quitting word, my late bound initializeme sub (modified), and a module level boolean variable.

    For me, word remains open when it should, correct document adding, if user closes their instance of word it checks and recreates a new one, etc.

    Let me know if it works for you.

    Affected subs/code lines:

    vb Code:
    1. Private mbKillMe As Boolean
    2.  
    3. Public Sub OpenWord()
    4.  
    5.     'Dim hwnd As Long
    6.     Dim nRpt As Integer
    7.    
    8.     On Error GoTo ErrorRoutine
    9.    
    10. StartOver:
    11.     InitializeMe
    12.  
    13.     Exit Sub
    14.  
    15. ErrorRoutine:
    16.     Select Case Err.Number
    17.         Case -2147023174
    18.             ' The user has manually shut down Word, so we need to
    19.             ' clean up and then restart Word.
    20.             For nRpt = 1 To wdApp.Documents.Count
    21.                 wdApp.Documents(nRpt).Close SaveChanges:=wdDoNotSaveChanges
    22.             Next nRpt
    23.             wdApp.Quit
    24.             Set wdApp = Nothing
    25.             Resume StartOver
    26.         Case 462 'Server not available - why??? 'Fixed but keep error handling just in case
    27.             Resume Next
    28.         Case Else
    29.             DisplayError "OpenWord"
    30.     End Select
    31.  
    32. End Sub
    33. Public Sub InitializeMe()
    34.     On Error Resume Next
    35.     '<INITIALIZE WORD>
    36.     Set wdApp = GetObject(, "Word.Application")
    37.     If TypeName(wdApp) <> "Nothing" And TypeName(wdApp) <> "Object" Then
    38.         Set wdApp = GetObject(, "Word.Application")
    39.         mbKillMe = False
    40.     Else
    41.         Set wdApp = CreateObject("Word.Application")
    42.         mbKillMe = True
    43.     End If
    44. End Sub
    45.  
    46. Public Sub Hotkey_Hit()
    47.     Dim oDoc As Object
    48.     OpenWord
    49.    
    50.     SendKeys "^c", True
    51.    
    52.     With wdApp
    53. '        .Visible = True
    54.         Set oDoc = .Documents.Add(, , wdNewBlankDocument, True)
    55.         oDoc.Range.PasteAndFormat (wdPasteDefault)
    56. '        .Selection.PasteAndFormat (wdPasteDefault)
    57.         oDoc.Range.WholeStory
    58. '        .Selection.WholeStory
    59.         oDoc.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
    60. '        .Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
    61.         oDoc.Range.Copy
    62. '        .Selection.Copy
    63.         oDoc.Close SaveChanges:=wdDoNotSaveChanges
    64.         Set oDoc = Nothing
    65.         If mbKillMe = True Then
    66.             .Quit
    67.             Set wdApp = Nothing
    68.         End If
    69.     End With
    70.  
    71. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why does this work only once

    If you are using Alt_c then you are probably using the code that I posted in the Utility forum which did behave the way you described and I was able to change that with the Documents.Count code but then I ran across the two-times-with-Word-open problem which caused me to start this thread.

    I'll take a look at your code however.

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why does this work only once

    Yes, I got your code from the UB download and using Alt+C
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why does this work only once

    I forgot to add the constant definitions for when using late bindings...
    vb Code:
    1. Const wdNewBlankDocument = 0
    2. Const wdPasteDefault = 0
    3. Const wdNumberParagraph = 1
    4. Const wdDoNotSaveChanges = 0
    What is error 4605?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why does this work only once

    Quote Originally Posted by RobDog888
    I forgot to add the constant definitions for when using late bindings...
    vb Code:
    1. Const wdNewBlankDocument = 0
    2. Const wdPasteDefault = 0
    3. Const wdNumberParagraph = 1
    4. Const wdDoNotSaveChanges = 0
    What is error 4605?
    See my post #11.


    Why do I need the constants? Aren't they built in?

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why does this work only once

    Found it. Are you using Word 2000?

    CAUSE
    One of these error messages may appear when no documents are currently open, or the document that you are referencing is not open. Word can change only the properties of an open (or visible) document.
    http://support.microsoft.com/kb/290934

    Also in Word 2002:
    http://support.microsoft.com/kb/288424/

    Worrd 2003:
    http://support.microsoft.com/kb/896987/
    Looks like you need Office 2003 Service Pack 2 for the fix on this version.



    Edit: Yes they are built in but only defined when using Early Binding. When using Late Binding you need to define all constants.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why does this work only once

    Thanks for every-one's help. There are bloodstains on the wall from me beating my head against it but I was able to fix the problem by doing this.

    vb Code:
    1. On Error Resume Next
    2.     '<INITIALIZE WORD>
    3. '    Set wdApp = GetObject(, "Word.Application")
    4. '    If TypeName(wdApp) <> "Nothing" Then
    5. '        Set wdApp = GetObject(, "Word.Application")
    6. '    Else
    7.         Set wdApp = CreateObject("Word.Application")
    8. '    End If
    In other words by always creating my own temporary word object rather than trying to share any existing one.

  22. #22
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why does this work only once

    What version of word were you using it on? It worked fine for me on 2007.

    Dont you get a time delay creating the app object each time?

    The other issues are fixed too now, correct?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  23. #23

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Why does this work only once

    1. 2002

    2. Not a noticeable one (perhaps because it's not visible)

    3. Yes.

    There's one really weird thing left but I'm not going to worry about it. When I posted this
    vb Code:
    1. '<INITIALIZE WORD>
    2. '    Set wdApp = GetObject(, "Word.Application")
    3. '    If TypeName(wdApp) <> "Nothing" Then
    4. '        Set wdApp = GetObject(, "Word.Application")
    5. '    Else
    6.         Set wdApp = CreateObject("Word.Application")
    7. '    End If
    My actual code didn't have the GetObject line commented out but when I saw what I had posted I said to myself "self, you don't need that because of the CreateObject line that follows" and I made it a comment here. I then went back to the program and changed it there and it no longer worked! Strange. I've changed it back and it works again.

  24. #24
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Why does this work only once

    Oh ya, and you may want to check for the word version and if word is installed on the system too.

    Maybe there was a hidden instance of word that was giving the issue?

    Glad the other issues are fixed but I still wonder why the app object is so troublesome. I still have a minor issue on my code similar to this too.

    Maybe with my updated code I have been working on, I can fix the getobject issue.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  25. #25

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