Visual Basic open/print word document?
Question: Hello, I am writing this code to open and print a Microsoft Word Document from Excel. I can open and print if I have the exact filename (Doc1.doc). However I will be changing the filename version a lot so I needed to make it recognize Doc*.dot. When I ran the code, I would get 'Run time error 5151 Word was unable to read this document. It may be corrupt Try one or more of the following: *Open and repair the file *Open the file with Text Recovery converter' This is the code I used Dim wdApp As Object Dim wdDoc As Object Set wdApp = CreateObject("Word.application") Set wdDoc = wdApp.Documents.Open("S:\EGB Gaming Lab\Training Manual\Testing Documents\Testing Checklists\Doc*.doc") wdApp.Visible = True Set wdDoc = Nothing Set wdApp = Nothing I tried the code Nomdae Plume provided but i got this other error Run time error 5174.
Best Answers: Visual Basic open/print word document?
Wildcards such as * are generally not expected by an application such as Word or Excel, so Word was looking for a file with exactly the name you gave it, asterisk and all. You have to make the Excel code smart enough to get the right name and send it to Word. Hope that helps.
The Text property in your textbox is of type String. You need to convert your Integer to a String. Also, whatever comes out of the Sqrt function, even if the result is a whole number, will be of type Double so you would need to convert that to an Integer if that's what you want. Example: Dim X As Double TextBox1.Text = CStr(CInt(Math.Sqrt(X))) This is off the top of my head. Hopefully I got the syntax correct. Good luck.
You need to specify an exact file name. Try something like this: Dim wdApp As Object Dim wdDoc As Object Dim fileName As String fileName = Dir("S:\EGB Gaming Lab\Training Manual\Testing Documents\Testing Checklists\Doc*.doc") If fileName <> "" Then Set wdApp = CreateObject("Word.application") Set wdDoc = wdApp.Documents.Open(fileName) wdApp.Visible = True Set wdDoc = Nothing Set wdApp = Nothing End If Good Luck!
i'm uncertain why your father can't open a notice rfile or why you may't save it in yet another format inclusive of rtf.at the beginning, all your father has to do is open OpenOffice and open the rfile from interior the honestly application particularly than double clicking on the record icon. If he is going to record, Open (the good way around) then substitute the record form on the backside of the window to All documents, he will see the .rfile and have the potential to open it with out issue. in addition, in case you record, Dave As (returned the good way, particularly than in basic terms clicking on save icon or CtrlS), navigate to the place you desire to save the rfile, call it then substitute the record form by utilising clicking on the downward arrow to the astounding of the record form field and choosing rtf. in spite of the undeniable fact that, analyzing your question returned, you're saying you won't be ready to save as an rtf or rfile!!! have to procure 2007 and for this reason saving as docx? no count, same comments word. you may save in .rfile or rtf or .txt or any variety of different formats. i think of the issue might desire to lie interior the reality that neither you nor your father are very knowledgeable on computers.
If you have your own answer to the question Visual Basic open/print word document?, then you can write your own version, using the form below for an extended answer.