none
Using Word from Excel vba RRS feed

  • Question

  • I am trying to move some text from Excel to Word. The code below (mostly copied from a question in this forum) opens Word but does not open the .docx file in word.  Word is open and no file, mine or a blank page, is displayed. Notice that I mistakenly typed C:\C:\ at the beginning of the file path.  If I (correctly I thought) type C:\ only once, there is a long delay executing the .Open statement and eventually an error message. "Microsoft Excel is waiting for another application to complete an OLE action."  At that point I am unable to terminate the Excel subroutine or close Excel without shutting down the computer.  What am I missing please.  Also, once the Word file is open, what command(s) do I need to paste the text into the Word document, show the Word document, and return to the Excel document execution?  I copied the file path (except the extra C:\) directly using copy in File Explorer to assure that it would be correct.  Thank you.

    Sub automateword()
    Dim WordApp As Object
    Dim Test As String

        Test = "This is a test"

        Set WordApp = CreateObject("Word.Application")
        WordApp.documents.Open "C:\C:\Users\Steve\Desktop\Personal\WordScape.docx"
        WordApp.Visible = True

    '  Paste Test in the word document?

    '  Show the Word document?

    '  Return to the Excel document?

    End Sub

        

    Steve

    Saturday, August 11, 2018 5:41 PM

Answers

  • Dim WordApp As Object
    Dim Test As String
        Test = "This is a test"
        Set WordApp = CreateObject("Word.Application")
        WordApp.documents.Open "C:\Users\JOAO\Desktop\web (4)\Consultoria.docm" '' change your path.
        WordApp.Visible = True
        WordApp.Selection.TypeText Text:=Test

    • Marked as answer by SteveL001 Monday, November 26, 2018 1:55 AM
    Sunday, November 25, 2018 11:26 PM
  • Sub Macro2()
     Dim WordApp As Object
    Dim Test As String
        Test = "xczc"
        If Application.CheckSpelling(Test) = True Then '' check the other parameters of the function checkspelling, you can create custom dictionaries and also ignore or not uppercase letters
       
            Set WordApp = CreateObject("Word.Application")
            WordApp.documents.Open "C:\Users\JOAO\Desktop\web (4)\Consultoria.docm" '' change your path.
            WordApp.Visible = True
            WordApp.Selection.TypeText Text:=Test
        End If
       
      
    End Sub


    Monday, November 26, 2018 3:09 AM

All replies

  • Dim WordApp As Object
    Dim Test As String
        Test = "This is a test"
        Set WordApp = CreateObject("Word.Application")
        WordApp.documents.Open "C:\Users\JOAO\Desktop\web (4)\Consultoria.docm" '' change your path.
        WordApp.Visible = True
        WordApp.Selection.TypeText Text:=Test

    • Marked as answer by SteveL001 Monday, November 26, 2018 1:55 AM
    Sunday, November 25, 2018 11:26 PM
  • Thanks. I would also like to find out if a single word of text, in VBA in Excel, is spelled correctly (ie, in the dictionaryn). I would like my VBA program to maintain control.  When I try spellcheck in Word, it marks the text and turns control over to the document.  Any ideas?

    Steve


    Monday, November 26, 2018 1:59 AM
  • Sub Macro2()
     Dim WordApp As Object
    Dim Test As String
        Test = "xczc"
        If Application.CheckSpelling(Test) = True Then '' check the other parameters of the function checkspelling, you can create custom dictionaries and also ignore or not uppercase letters
       
            Set WordApp = CreateObject("Word.Application")
            WordApp.documents.Open "C:\Users\JOAO\Desktop\web (4)\Consultoria.docm" '' change your path.
            WordApp.Visible = True
            WordApp.Selection.TypeText Text:=Test
        End If
       
      
    End Sub


    Monday, November 26, 2018 3:09 AM
  • Thanks again.  But back to the original question.  When I enter your code with my document name, my computer hangs up.  I get the message "Waiting for another application before completing the OLE action".  (The error wording is not completely correct).  I had to shut down the computer to regain control, and on restarting it opened both Excel and a new blank Word document.  Am I missing some parameter?  Thanks

    Steve

    Monday, November 26, 2018 3:31 AM
  • Reset

    I solved my own problem.  The Word file I was opening had some erroneous code in the document opening module.


    Steve

    Monday, November 26, 2018 2:01 PM