VBA code correction!

Closed
PM - Aug 21, 2009 at 06:49 AM
sharpman Posts 1021 Registration date Saturday May 23, 2009 Status Contributor Last seen October 20, 2010 - Aug 24, 2009 at 05:13 AM
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
Related:

3 responses

sharpman Posts 1021 Registration date Saturday May 23, 2009 Status Contributor Last seen October 20, 2010 183
Aug 23, 2009 at 11:15 AM
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
0
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??
0
sharpman Posts 1021 Registration date Saturday May 23, 2009 Status Contributor Last seen October 20, 2010 183
Aug 24, 2009 at 05:13 AM
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.
0