macro trouble

P

PJY

Hi Graham, Thanks so much for your input. Actually, what I am utimately
going for is a pdf of all the documents I have in the one folder. We create
the Word docs, then once the engineers have finalized those docs we convert
over to pdf to send to our vendor who then puts our specs on their website,
so I thought the easiest way would be to create one continuous Word doc, then
pdf that, as using the Adobe conversion takes so much time. We also put a
password on the Word docs (has to do with control issues), and we work on the
Word docs with track changes, which stay in the doc even once the document is
final. So, I have created a macro which removes the password, sets the track
changes view to final and then creates a pdf of the Word doc. This works very
well for everything except for the first file in the folder. Just for some
background - when I run the macro, I first set the Adobe printer as my
default printer, I then change the Adobe PDF output folder to match my
destination folder, and I uncheck view Adobe PDF results. If you have some
time, could you look at my macro and see if you can find my error. Thanks so
much for all your help!!

Sub RemoveProtectFinalPDF()
Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long

PathToUse = "U:\unprotect\"

On Error Resume Next

Documents.Close SaveChanges:=wdPromptToSaveChanges

FirstLoop = True

myFile = Dir$(PathToUse & "*.doc")

While myFile <> ""

Set myDoc = Documents.Open(PathToUse & myFile)

If FirstLoop Then

Dialogs(wdDialogToolsUnprotectDocument).Show

FirstLoop = False

Response = MsgBox("Do you want to process " & _
"the rest of the files in this folder", vbYesNo)
If Response = vbNo Then Exit Sub

Else

With Dialogs(wdDialogToolsUnprotectDocument)
ActiveDocument.Unprotect Password:="8678"
..Execute

End With

With ActiveWindow.View
..ShowRevisionsAndComments = False
..RevisionsView = wdRevisionsViewFinal
End With

ActivePrinter = "Adobe PDF"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True,
PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

End If

myDoc.Close SaveChanges:=wdSaveChanges

myFile = Dir$()

Wend

End Sub



:

Click to show or hide original message or reply text.
 
G

Graham Mayor

You have a first document loop that does nothing hence the first document is
ignored. The following should work for you.


Sub RemoveProtectFinalPDF()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim sPrinter As String
PathToUse = "U:\unprotect\"
On Error Resume Next
Documents.Close SaveChanges:=wdPromptToSaveChanges
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
myDoc.Unprotect "8678"
With ActiveWindow.View
.ShowRevisionsAndComments = False
.RevisionsView = wdRevisionsViewFinal
End With
ActivePrinter = "Adobe PDF"
myDoc.PrintOut
myDoc.Close SaveChanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

PJY

Hi Graham,
I just tried it out and it works like a charm - thank you again for your
help!!
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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