PDA

View Full Version : Printing to Adobe 7 and closing file



plarnold
10-05-2006, 09:03 AM
I have a macro that breaks a word document apart and saves each page as its own word file. As well as print the individual files to Adobe. I have upgraded my Adobe to 7 now my macro crashes on Application.Run MacroName:="CreatePDFAndCloseDoc"

Any suggestions?

fumei
10-05-2006, 10:27 AM
Impossible to suggest anything.

Don't know what "crashes" means. Your computer stops? You get error messages?

Don't know what is in CreatePDFAndCloseDoc.

As we can not see what is actually happening to you...maybe you can tell us?

geekgirlau
10-06-2006, 12:57 AM
The process for printing to a PDF in version 7 differs from both 5 and 6 - can you post the code you used previously? We need to see the code for CreatePDFAndCloseDoc.

plarnold
10-06-2006, 07:48 AM
I have changed the code and it prints to adobe but i have to click the save button. Can i add that feature to the code to save it automatically?

ub BreakIt()
Dim MainDoc As Document, SubDoc As Document, SectionNo%, sPath$

Set MainDoc = ActiveDocument
sPath = MainDoc.Path
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"

For SectionNo = 1 To ActiveDocument.Sections.Count
ActiveDocument.Sections(SectionNo).Range.Copy
Set SubDoc = Application.Documents.Add
SubDoc.Range.Paste
SubDoc.SaveAs sPath & Left(MainDoc.Name, Len(MainDoc.Name) - 4) & _
SectionNo & ".doc"
ActivePrinter = "Adobe PDF"
ActiveDocument.PrintOut
SubDoc.SaveAs sPath & Left(MainDoc.Name, Len(MainDoc.Name) - 4) & _
SectionNo & ".pdf"

ActiveDocument.Close

Next SectionNo
Set SubDoc = Nothing
Set MainDoc = Nothing
End Sub

plarnold
10-10-2006, 09:23 AM
I have changed the code and it prints to adobe but i have to click the save button. Can i add that feature to the code to save it automatically?

ub BreakIt()
Dim MainDoc As Document, SubDoc As Document, SectionNo%, sPath$

Set MainDoc = ActiveDocument
sPath = MainDoc.Path
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"

For SectionNo = 1 To ActiveDocument.Sections.Count
ActiveDocument.Sections(SectionNo).Range.Copy
Set SubDoc = Application.Documents.Add
SubDoc.Range.Paste
SubDoc.SaveAs sPath & Left(MainDoc.Name, Len(MainDoc.Name) - 4) & _
SectionNo & ".doc"
ActivePrinter = "Adobe PDF"
ActiveDocument.PrintOut
SubDoc.SaveAs sPath & Left(MainDoc.Name, Len(MainDoc.Name) - 4) & _
SectionNo & ".pdf"

ActiveDocument.Close

Next SectionNo
Set SubDoc = Nothing
Set MainDoc = Nothing
End Sub

fumei
10-10-2006, 06:33 PM
I am not familiar with saving a Word document to PDF - as I don't use it. Where exactly do you have the Save button?

Out of curiosity - does doing a SaveAs with the extension ".pdf" actually make a PDF?

Also out of curiosity, regarding the codeIf Right(sPath, 1) <> "\" Then sPath = sPath & "\"have you ever had the situation where the last character of .Path WAS "\"?

geekgirlau
10-10-2006, 09:00 PM
I have a Knowledge Base article (http://vbaexpress.com/kb/getarticle.php?kb_id=789) that works with Acrobat 5, but I was never able to get rid of the prompt with version 7 - you might have better luck.