I am wondering if this is possible maybe through some sort of VBA code or a batch script… I am trying to save all of the saved *.rep reports in a specific directory to PDF. I have found information on adding VB code in a macro to a single file and then when that file is opened, it saves to PDF but I would have to add the code to EVERY file in the directory…
Is there any way I can save/export them ALL to PDF in one step?
There is some code here … Save for all users that will interatively process all documents in a folder. Substituting .ExportAsPDF for .SaveAs should get you close.
In a new document, create a variable name . It can be displayed in your report if needed. Create a new VBA module (Alt-F11, Insert Module…), and copy in the following code.
Instructions are as follows …
Option Explicit
Sub SaveForAllUsers()
Dim FileList As New Collection
Dim FileName As Variant
Dim Doc As Document
On Error GoTo ErrorHandler
ThisDocument.DocumentVariables("Messages").Formula = "Messages:"
Call BuildList(FileList, ThisDocument.path & "\")
On Error GoTo FileErrors
For Each FileName In FileList
Set Doc = Application.Documents.Open(FileName, True, False)
Call Doc.SaveAs(Doc.FullName, True)
Call Doc.Close(boDontSave)
Next FileName
CleanUp:
On Error Resume Next
Exit Sub
ErrorHandler:
MsgBox Err.Number & ": " & Err.Description
Resume CleanUp
FileErrors:
ThisDocument.DocumentVariables("Messages").Formula = _
ThisDocument.DocumentVariables("Messages").Formula & vbCrLf & _
FileName & ": " & Err.Number & " - " & Err.Description
Resume Next
End Sub
Private Sub BuildList(FileList As Collection, PathName As Variant)
Dim DirList As New Collection
Dim DirName As Variant
Dim FileName As String
On Error GoTo ErrorHandler
FileName = Dir(PathName & "*.rep")
Do Until FileName = vbNullString
If PathName & FileName <> ThisDocument.FullName Then
Call FileList.Add(PathName & FileName)
End If
FileName = Dir
Loop
DirName = Dir(PathName, vbDirectory)
Do Until DirName = vbNullString
If (GetAttr(PathName & DirName) And vbDirectory) = vbDirectory And _
DirName <> "." And DirName <> ".." Then
Call DirList.Add(PathName & DirName & "\")
End If
DirName = Dir
Loop
For Each DirName In DirList
Call BuildList(FileList, DirName)
Next DirName
CleanUp:
On Error Resume Next
Exit Sub
ErrorHandler:
MsgBox Err.Number & ": " & Err.Description
Resume CleanUp
End Sub
I think I’m just about there… I have substituted the code for PDF but it insists on keeping the .rep prefix whne it saves the filename. Ex) FileName.rep.pdf
Do you have any ideas on how to strip that out? I tried some code to take only a portion of the filename but it seems like you need it there… it didn’t save when I did that.
Sub SaveForAllUsers()
Dim FileList As New Collection
Dim FileName As Variant
Dim Doc As Document
Dim sFileName As Variant
On Error GoTo ErrorHandler
ThisDocument.DocumentVariables("Messages").Formula = "Messages:"
Call BuildList(FileList, ThisDocument.Path & "\")
On Error GoTo FileErrors
For Each FileName In FileList
Set Doc = Application.Documents.Open(FileName, True, False)
Set Doc = ActiveDocument
sFileName = FileName & ".pdf"
Call Doc.ExportAsPDF(sFileName)
Call Doc.Close(boDontSave)
Next FileName