D
Dan B
Hello All.
I while back, Grham Mayor helped me with the code below (in fainess he wrote
most of it). It's supposed print PDF files of a bunch of Word docs that I
already have made. The word docs are question answer sheets with the answers
in text boxes - by chnaging the font colour of text in text boxes to white, I
can hide the answers. The idea is to end up with a 'questions only' version
and 'questions & answers' version of each Word doc in PDF form (all automated
to the point where you just choose the floder of docs to convert).
Graham did a great job to the point where it works at his end but only
sometimes at my end and with mixed success.
Can anybody help with this code or suggest another way?
I'm running Word 2003 and Acrobat Pro 8 on Win XP.
Please consider that I can program a bit in other languages but have no
knowledge of VB.
Here's the exisiting Macro code:
Sub BatchPrint2PDF()
Dim DocList As String
Dim DocDir As String
Dim sPrinter As String
Dim aShape As Shape
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder containing the documents to be printed to PDF
and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
DocDir = fDialog.SelectedItems.Item(1)
If Right(DocDir, 1) <> "\" Then DocDir = DocDir + "\"
End With
On Error Resume Next
MkDir DocDir & "Temp\"
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
'First loop creates the extra documents in the temporary folder
DocList = Dir$(DocDir & "*.doc")
Do While DocList <> ""
Documents.Open DocList
With ActiveDocument
sname = Left$(.Name, (Len(.Name) - 6)) & "-a.doc"
.SaveAs DocDir & "Temp\" & sname
.SaveAs DocList
sname = Left$(.Name, (Len(.Name) - 6)) & "-q.doc"
.SaveAs DocDir & "Temp\" & sname
.SaveAs DocList
.Close SaveChanges:=wdDoNotSaveChanges
End With
DocList = Dir$()
Loop
'Second loop formats all the files ending in q.doc to lose the answers
DocList = Dir$(DocDir & "Temp\*q.doc")
Do While DocList <> ""
ChDir DocDir & "Temp\"
Documents.Open DocList
With ActiveDocument
For Each aShape In .Shapes
If aShape.Type = msoTextBox Then
With aShape
If .TextFrame.HasText Then
.TextFrame.TextRange.Font.Color = wdColorWhite
End If
End With
End If
Next
.Close SaveChanges:=wdSaveChanges
End With
DocList = Dir$()
Loop
'Final loop outputs all the document files in the temp folder to PDF
DocList = Dir$(DocDir & "Temp\*.doc")
Do While DocList <> ""
ChDir DocDir & "Temp\"
Documents.Open DocList
ActivePrinter = sPrinter
With Dialogs(wdDialogFilePrintSetup)
sPrinter = .Printer
.Printer = "Adobe PDF"
.DoNotSetAsSysDefault = True
.Execute
End With
With ActiveDocument
.PrintOut
ActivePrinter = sPrinter
.Close SaveChanges:=wdDoNotSaveChanges
End With
DocList = Dir$()
Loop
End Sub
I while back, Grham Mayor helped me with the code below (in fainess he wrote
most of it). It's supposed print PDF files of a bunch of Word docs that I
already have made. The word docs are question answer sheets with the answers
in text boxes - by chnaging the font colour of text in text boxes to white, I
can hide the answers. The idea is to end up with a 'questions only' version
and 'questions & answers' version of each Word doc in PDF form (all automated
to the point where you just choose the floder of docs to convert).
Graham did a great job to the point where it works at his end but only
sometimes at my end and with mixed success.
Can anybody help with this code or suggest another way?
I'm running Word 2003 and Acrobat Pro 8 on Win XP.
Please consider that I can program a bit in other languages but have no
knowledge of VB.
Here's the exisiting Macro code:
Sub BatchPrint2PDF()
Dim DocList As String
Dim DocDir As String
Dim sPrinter As String
Dim aShape As Shape
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder containing the documents to be printed to PDF
and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
DocDir = fDialog.SelectedItems.Item(1)
If Right(DocDir, 1) <> "\" Then DocDir = DocDir + "\"
End With
On Error Resume Next
MkDir DocDir & "Temp\"
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
'First loop creates the extra documents in the temporary folder
DocList = Dir$(DocDir & "*.doc")
Do While DocList <> ""
Documents.Open DocList
With ActiveDocument
sname = Left$(.Name, (Len(.Name) - 6)) & "-a.doc"
.SaveAs DocDir & "Temp\" & sname
.SaveAs DocList
sname = Left$(.Name, (Len(.Name) - 6)) & "-q.doc"
.SaveAs DocDir & "Temp\" & sname
.SaveAs DocList
.Close SaveChanges:=wdDoNotSaveChanges
End With
DocList = Dir$()
Loop
'Second loop formats all the files ending in q.doc to lose the answers
DocList = Dir$(DocDir & "Temp\*q.doc")
Do While DocList <> ""
ChDir DocDir & "Temp\"
Documents.Open DocList
With ActiveDocument
For Each aShape In .Shapes
If aShape.Type = msoTextBox Then
With aShape
If .TextFrame.HasText Then
.TextFrame.TextRange.Font.Color = wdColorWhite
End If
End With
End If
Next
.Close SaveChanges:=wdSaveChanges
End With
DocList = Dir$()
Loop
'Final loop outputs all the document files in the temp folder to PDF
DocList = Dir$(DocDir & "Temp\*.doc")
Do While DocList <> ""
ChDir DocDir & "Temp\"
Documents.Open DocList
ActivePrinter = sPrinter
With Dialogs(wdDialogFilePrintSetup)
sPrinter = .Printer
.Printer = "Adobe PDF"
.DoNotSetAsSysDefault = True
.Execute
End With
With ActiveDocument
.PrintOut
ActivePrinter = sPrinter
.Close SaveChanges:=wdDoNotSaveChanges
End With
DocList = Dir$()
Loop
End Sub