Print Error, Word.Application : Command Failed!

  • Thread starter Thread starter Kevin993
  • Start date Start date
K

Kevin993

Guest
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

Continue reading...
 
Back
Top