Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2013, 08:27 AM
bville bville is offline Word Macro to publish document as pdf (Word 2010) Windows 8 Word Macro to publish document as pdf (Word 2010) Office 2010 32bit
Novice
Word Macro to publish document as pdf (Word 2010)
 
Join Date: Apr 2013
Posts: 2
bville is on a distinguished road
Question Word Macro to publish document as pdf (Word 2010)

In Word 2010, the only way to save word doc (.docx) and publish it as pdf (pdf preview) is as follows :
File > Save & Send > Create PDF/XPS Document > Create PDF/XPS > Publish

Above series of clicks opens a window titled 'Publish as PDF or XPS' with original file name but file type as PDF (in the same path or directory as original .docx file).
I recorded a macro using the series of steps above by opening a blank doc1.docx file. The macro runs perfectly well. My problem is that when i run this macro on any other word file it still ends up at c:user/documents directory as doc1.pdf. I would like the macro to create pdf file with same file name and in the same directory and show the pdf preview (as the series of clicks above does it). Can someone help?

(File > Save as > PDF does not publish or bring up the pdf preview but simply saves it to the same directory with same file name but pdf extension)

The VBA code generated in my macro is:
Code:
Sub pdf()
 
' pdf Macro
  ActiveDocument.ExportAsFixedFormat OutputFileName:= _
    "C:\Users\username\Documents\Doc1.pdf", ExportFormat:=wdExportFormatPDF, _
    OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
    wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
    IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
    wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
    True, UseISO19005_1:=False
End Sub
I would appreciate any help or hopefully a VBA code (macro) that would save the .docx file, convert it to .pdf with same file name and publish (pdf preview).
Thanks in advance
(Since i am posting first time here - i dont know if the replies will be sent to my email or i have to access the forum everytime or if i can give my email address here in the post?)

Last edited by macropod; 04-10-2013 at 02:12 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 04-10-2013, 02:21 PM
macropod's Avatar
macropod macropod is offline Word Macro to publish document as pdf (Word 2010) Windows 7 64bit Word Macro to publish document as pdf (Word 2010) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub PDF()
 
' pdf Macro
Dim StrName As String
With ActiveDocument
  StrName = .FullName
  StrName = Left(StrName, InStrRev(StrName, ".")) & "pdf"
  .ExportAsFixedFormat OutputFileName:=StrName, UseISO19005_1:=False, _
    ExportFormat:=wdExportFormatPDF, OptimizeFor:=wdExportOptimizeForPrint, _
    OpenAfterExport:=True, Range:=wdExportAllDocument, From:=1, To:=1, _
    Item:=wdExportDocumentContent, IncludeDocProps:=True, _
    KeepIRM:=True, CreateBookmarks:=wdExportCreateNoBookmarks, _
    DocStructureTags:=True, BitmapMissingFonts:=True
End With
End Sub
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-11-2013, 03:30 PM
bville bville is offline Word Macro to publish document as pdf (Word 2010) Windows 8 Word Macro to publish document as pdf (Word 2010) Office 2010 32bit
Novice
Word Macro to publish document as pdf (Word 2010)
 
Join Date: Apr 2013
Posts: 2
bville is on a distinguished road
Default

Works perfectly!
Thanks Paul.
Reply With Quote
Reply

Tags
macro vba word, publish pdf



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Macro to publish document as pdf (Word 2010) MAcro to List all the Font & its size in a word document shaukat74 Word VBA 1 01-29-2013 09:34 PM
Word 2007 can't connect and publish to WordPress Danielm Word 0 10-23-2012 12:38 AM
Word Macro to publish document as pdf (Word 2010) Macro to read word document harishankar.selvaraju Excel Programming 1 06-14-2012 03:48 AM
Save or publish as Word (or other format) - All notes AND slide text jfreema PowerPoint 0 06-18-2010 11:49 AM
Word 2003 macro to Word 2007 to 2010 to... maruapo Word VBA 0 06-04-2010 03:43 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft