none
Print Error, Word.Application : Command Failed! RRS feed

  • Question

  • Greetings,

    I use the following code to print with Word.Application :

                    Dim wordApp = New Word.Application With {.Visible = False}
    
                    Dim oDocs As Word.Document = wordApp.Documents.Open(System.Windows.Forms.Application.StartupPath & "\s.docx",,,, "Mypass")
    
                
    
    
                    oDocs.Bookmarks.Item("cdate").Range.Text = txtdate.text
    
    
                    Dim rtx As New RichTextBox With {.Name = "rtx", .Multiline = True}
    
                    For Each x In dgv1.SelectedRows
    
    
                        rtx.Text &= x.Cells(0).Value.ToString & "_" & x.Cells(8).Value.ToString & vbNewLine 
    
    
    
    
    
                    Next
    				
                    oDocs.Bookmarks.Item("crecord").Range.Text = rtx.Text
    
    
    
                    Dim p As New PrintDialog
                    If p.ShowDialog = System.Windows.Forms.DialogResult.OK Then
    
    
    
                        wordApp.WordBasic.FilePrintSetup(Printer:=p.PrinterSettings.PrinterName, DoNotSetAsSysDefault:=1)
    
    
    
    
                    End If
    
    
                    wordApp.PrintOut(False)
                    wordApp.Quit(False)
                    Marshal.FinalReleaseComObject(wordApp)
                    wordApp = Nothing
    
    

    The code above is tested and it works in my machine (Windows 8.1, 64bit , Office 2016), also tested in another machine (laptop) running the same OS and Office version. But one of my users face an error : "Command Failed" when running this code (I put the code in "Try Catch Ex as Exception EndTry" and the result is the error I mentioned).

    He uses Windows7, Office 2010. What could be the cause ?

    Thanks in advanced

    Friday, November 15, 2019 8:12 PM

Answers

  • With any Office automation running on various computers there is always the chance of a) different Interop versions b) dependencies on the Interop DLL's. This boils down to visiting a good computer and a bad computer and do comparisons on things.

    This is a solid reason to look at Open Word XML were there much less of a chance for versioning issues as all dependencies are in the app folder not from the system.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Well, I use Advanced Installer which detects dependencies by importing Visual Studio Solution. How can I check the  Interop version differences on different machines  and how should I install the one  that runs well in my machine, in another machine that faces the problem?

    " visiting a good computer and a bad computer and do comparisons on things."

    making comparison on what?

    I was think running Dependencies utility. Visiting may be done in person or in a corp environment via a remote login. In regards to your installer, no software is perfect and should be double checked along with computers get updated all the time and may have had an update after your app was installed.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Kevin993 Saturday, November 23, 2019 11:35 AM
    Friday, November 15, 2019 9:27 PM
    Moderator

All replies

  • With any Office automation running on various computers there is always the chance of a) different Interop versions b) dependencies on the Interop DLL's. This boils down to visiting a good computer and a bad computer and do comparisons on things.

    This is a solid reason to look at Open Word XML were there much less of a chance for versioning issues as all dependencies are in the app folder not from the system.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, November 15, 2019 8:16 PM
    Moderator
  • With any Office automation running on various computers there is always the chance of a) different Interop versions b) dependencies on the Interop DLL's. This boils down to visiting a good computer and a bad computer and do comparisons on things.

    This is a solid reason to look at Open Word XML were there much less of a chance for versioning issues as all dependencies are in the app folder not from the system.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Well, I use Advanced Installer which detects dependencies by importing Visual Studio Solution. How can I check the  Interop version differences on different machines  and how should I install the one  that runs well in my machine, in another machine that faces the problem?

    " visiting a good computer and a bad computer and do comparisons on things."

    making comparison on what?

    • Edited by Kevin993 Friday, November 15, 2019 8:34 PM
    Friday, November 15, 2019 8:31 PM
  • With any Office automation running on various computers there is always the chance of a) different Interop versions b) dependencies on the Interop DLL's. This boils down to visiting a good computer and a bad computer and do comparisons on things.

    This is a solid reason to look at Open Word XML were there much less of a chance for versioning issues as all dependencies are in the app folder not from the system.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Well, I use Advanced Installer which detects dependencies by importing Visual Studio Solution. How can I check the  Interop version differences on different machines  and how should I install the one  that runs well in my machine, in another machine that faces the problem?

    " visiting a good computer and a bad computer and do comparisons on things."

    making comparison on what?

    I was think running Dependencies utility. Visiting may be done in person or in a corp environment via a remote login. In regards to your installer, no software is perfect and should be double checked along with computers get updated all the time and may have had an update after your app was installed.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Kevin993 Saturday, November 23, 2019 11:35 AM
    Friday, November 15, 2019 9:27 PM
    Moderator