how do I print .doc files from a list of pathnames in a spreadshee

D

Dal

I have list of .doc and .txt files in a spreadsheet. eg:

c:\myfolder\myfile1.doc
c:\myfolder\myfile2.doc
c:\myfolder\myfile3.txt

I want to run a macro that prints the files without opening the application.
i.e. I want to use a macro to effectively do the same as what happens when
you right click a file icon in windows explorer and select the 'print' option.

Any help appreciated.

Thanks

Dal
 
R

Ron de Bruin

hi Dal

With the path/file name in each cell in A1:A3 try this

Sub test()
Dim WD As Object
Dim cell As Range
For Each cell In Range("A1:A3")
If cell.Value <> "" Then
If Dir(cell.Value) <> "" Then
Set WD = CreateObject("Word.Application")
WD.Documents.Open (cell.Value)
WD.ActiveDocument.PrintOut Background:=False
WD.ActiveDocument.Close
WD.Quit
Set WD = Nothing
End If
End If
Next cell
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top