Create VBA/Macro to Convert MS Word into PDF

L

leelomei

Hi All,

I have many word files (around 200) and would like to convert them
into pdf format (I have Adobe pdf convertor).

I would like to create a VBA/macro in Word to do so.

I want the VBA code to do the followings:

1. I would like to put a name (e.g. "John Dude") in the first line of
the first page of each word file
2. Convert the word files into pdf format
3. Set the same password to open the pdf for all files (and the other
password to change the security)
4. Save the pdf file as the same name as the word file.

Would you please tell me how to do that? Thank you very much for your
help in advance. It is greatly appreciated!

Should you want me to clarify any unknowns, please post your questions
here. Thanks!

Best wishes,

Lee
 
D

Doug Robbins - Word MVP on news.microsoft.com

There are a couple of preparatory steps that you will need to take in the
Printer Properties dialog for the Adobe PDF Printer

1. Set Adobe PDF Security to "Use the last known security settings" and
then click on the Edit button and supply the required passwords.

2. Uncheck the "View Adobe PDF Results"

3. Uncheck the "Prompt for Adobe PDF filename" (Adobe will then use the
document filename as the PDF filename)

4. Uncheck the "Ask to Replace existing PDF file"

Best also to set the Adobe PDF printer as the Windows default Printer at
least while you are wanting to do this

Put all of the files that you want to process into the one folder by
themselves.

Then run a macro containing the following code:

Dim fname As String
Dim PathToUse As String
Dim Source As Document
Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Select the folder containing the files."
If .Show = -1 Then
PathToUse = .SelectedItems(1) & "\"
Else
End If
End With
Set fd = Nothing
If Len(PathToUse) = 0 Then
Exit Sub
End If
fname = Dir$(PathToUse & "*.doc*")
While fname <> ""
Set Source = Documents.Open(PathToUse & fname)
With Source
.Range.InsertBefore "John Dude" And vbCr
.Save
.PrintOut False
.Close wdDoNotSaveChanges
End With
fname = Dir$()
Wend



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
L

leelomei

Hi Doug,

Great work! Your help is greatly appreciated!

I have a question:

1. How can I set the passwords?
2. Instead of the first line, I would like to insert John Dude in the
third line. How can I do that?

Many thanks with your help!

Best regards,

Lee
 
D

Doug Robbins - Word MVP on news.microsoft.com

You set the Password in the Printer Properties dialog by clicking on the
Edit button and supplying the required passwords before running the macro.

To insert John Dude as the third line (paragraph) in the document, replace
the line

..Range.InsertBefore "John Dude" And vbCr

with

..Paragraphs(3).Range.InsertBefore "John Dude" And vbCr

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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