VBA code correction! [Closed]

Report
-
Posts
1021
Registration date
Saturday May 23, 2009
Status
Contributor
Last seen
October 20, 2010
-
Hello,

Does anyone know how i can amend the below code to printout a notepad file instead of a word document??

Sub PrintWordDocument()
Dim wrdApp As Object
Dim wrdDoc As Object
Dim myDocName As String
Dim myPrintBackground As Boolean


myDocName = "C:\transactions.txt"
Set wrdApp = CreateObject("Word.Application") 'I think its something to do with the code on this line

wrdApp.Visible = True 'Use this if you want it for testing.
Set wrdDoc = wrdApp.documents.Open(Filename:=myDocName)
myPrintBackground = wrdApp.Options.printbackground
wrdApp.Options.printbackground = False
wrdDoc.PrintOut
wrdApp.Options.printbackground = myPrintBackground
wrdDoc.Close savechanges:=False
wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub

3 replies

Posts
1021
Registration date
Saturday May 23, 2009
Status
Contributor
Last seen
October 20, 2010
182
Set wrdApp = CreateObject("Word.Application") 'I think its something to do with the code on this line

what happens if you put notepad.application whare the word.application is
It brings up an error on that line if i put notepad.application. You have any idea's on how to get it to work with a notepad file??
Posts
1021
Registration date
Saturday May 23, 2009
Status
Contributor
Last seen
October 20, 2010
182
sorry, not a vba guru, but if you look at this link
http://www.bigresource.com/VB-Printing-to-Notepad-and-Open-with-results-Resolved--3WiQDBj6YB.html

it may be of some assistance in your quest.

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!