How do I set the default name (ie. to something other than DocumentX)

N

Nelson F.

I am using Word to create reports/letters/etc that I need to save as PDF
files. I do not want to save the DOC files at all. My basic methodology now
is to do this:

-Open existing doc
-update fields
-print to Adobe PDF file
-close document

The problem is that Adobe PDF always assumes the document's filename as it's
naming convention - in Word's case it defaults to "DocumentX' (where X is a
number) as the filename and consequently the output file is named
DocumentX.PDF.

I have tried changing the title of the document as well as the caption but
nothing works. As a matter of fact this can be duplicated by openeing a new
document and performing the steps manually or running this VBA code:

sName = "My custom name"

Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0

With Dialogs(wdDialogFileSummaryInfo)
.Title = sName
.Execute
End With

ActiveDocument.ActiveWindow.Caption = sName

If you now try to close the document it says "Save changes to DocumentX?"
even though the title and caption have been changed to "My custom name"...
BUT if you try to save the document it correctly shows "My custom name" as
the default...

I assume that the text DocumentX must be stored somewhere internally but I
cannot find it. I would really rather not save this document and have to
deal with problems of existing and in-use documents etc...

Any suggestions? Can I change the filename without actually saving the file?
 
M

Mark Baird

Prints the document to file using Acrobat Distiller and
then tells Acrobat Distiller to create a PDF.

You can modify the name of the output file. This code
currently uses the activedocument name.


Mark

Set a reference to the following.
C:\Program Files\Adobe\Acrobat 4.0\Distillr\ACRODIST.EXE

Option Explicit
Public WithEvents objDistiller As PdfDistiller

Public Function ConvertToPDF(objDocument As Document,
strType As String) As String

Dim strActivePrinter As String
Dim strFullName As String
Dim objDistiller As New PdfDistiller
Dim blnSuccessfull As Boolean
Dim strPDFName As String
Dim strPDFCreationInformation As String

On Error GoTo HandleErr

strPDFCreationInformation = "...Creating " & strType
& " PDF..."

With frmWait
'.Show
.lblUpdate = strPDFCreationInformation
.Repaint
End With
DoEvents


'***Get the name of the active printer
strActivePrinter = ActivePrinter
strFullName = objDocument.FullName
strFullName = Mid$(strFullName, 1, InStr(1,
strFullName, ".") - 1)

'***Set the name to _p or _t
If strType = "ScreenOptimized" Then
strFullName = strFullName & "_t"
ElseIf strType = "PressOptimized" Then
strFullName = strFullName & "_p"
End If

strPDFName = strFullName & ".pdf"
'***change printer to Distiller and print out active
document
ActivePrinter = "Acrobat Distiller"

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

frmWait.Repaint
blnSuccessfull = objDistiller.FileToPDF(strFullName,
strPDFName, strType)
frmWait.Repaint

' If the PDF creation was successful return the name
of the PDF file.
' If it was not successfull a zero byte string is
returned.
If blnSuccessfull Then
ConvertToPDF = strPDFName
With frmWait
.lblUpdate = "...Inserting Banner..."
.Repaint
End With

App.CloseAllDocs
End If

Set App = Nothing

' Error handling block added by Error Handler Add-In. DO
NOT EDIT this block of code.
' Automatic error handler last updated at 08-08-2002
12:58:13 'ErrorHandler:$$D=08-08-
2002 'ErrorHandler:$$T=12:58:13
HandleErr:
If Err.Number <> 0 Then
Select Case Err.Number
Case 5216
MsgBox "Could not find Acrobat Distiller",
vbCritical, "ERROR"
Case Else
MsgBox "Error " & Err.Number & ": " &
Err.Description,
vbCritical, "Module1.PrintPDF" 'ErrorHandler:$$N=Module1.
PrintPDF
End Select
End If
' End Error handling block.

' Clean up
Set objDistiller = Nothing
ActivePrinter = strActivePrinter


End Function
 

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