Visual Basic open/print word document?

Visual Basic open/print word document? Topic: Visual Basic open/print word document?
May 20, 2019 / By Arista

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.

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.

Add a Question


Popular Question