Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2017, 10:27 AM
ekimisme ekimisme is offline Help with Macro to Save Word File as PDF in Specific Location Windows XP Help with Macro to Save Word File as PDF in Specific Location Office 2010 32bit
Novice
Help with Macro to Save Word File as PDF in Specific Location
 
Join Date: Jun 2017
Posts: 1
ekimisme is on a distinguished road
Default Help with Macro to Save Word File as PDF in Specific Location

Hi all,

I am trying to create a macro that automatically saves a word file from Word 2010 as a PDF to my desktop without any popups or further prompts.

The problem is that my work computer is constantly saving documents to different locations (even though my default save location is the desktop), so if the macro does not specify a folder, the PDF will go to whatever the last used folder was. What I have below works for creating the PDF, but not the location. The location I want is "C:\Users\XMMS\Desktop\". Any suggestions how I can upgrade my Macro below to get the right location every time?

Sub Print1()
'
' Silent Save_to_PDF Macro
'
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
Replace(ActiveDocument.FullName, ".docx", ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _


wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
'
End Sub



Thanks!!
Reply With Quote
  #2  
Old 06-07-2017, 10:40 PM
gmayor's Avatar
gmayor gmayor is offline Help with Macro to Save Word File as PDF in Specific Location Windows 10 Help with Macro to Save Word File as PDF in Specific Location Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will save to the current user's desktop. Note that you should be using the document's name not the fullname, which includes the path. Where the document has not been saved, the PDF will be saved as Documentn.pdf
Code:
Sub Print1()
'
' Silent Save_to_PDF Macro
Dim strPath As String
Dim strName As String
    strPath = Environ("USERPROFILE") & "\Desktop\"
    strName = Replace(ActiveDocument.Name, ".docx", ".pdf")
    ActiveDocument.ExportAsFixedFormat _
            OutputFileName:=strPath & strName, _
            ExportFormat:=wdExportFormatPDF, _
            OpenAfterExport:=False, _
            OptimizeFor:=wdExportOptimizeForPrint, _
            Range:=wdExportAllDocument, _
            Item:=wdExportDocumentContent, _
            IncludeDocProps:=False, _
            KeepIRM:=True, _
            CreateBookmarks:=wdExportCreateNoBookmarks, _
            DocStructureTags:=True, _
            BitmapMissingFonts:=True, _
            UseISO19005_1:=False
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Macro to Save Word File as PDF in Specific Location Macro to check the existence of a word docx file and create a new word file with specific content. staicumihai Word VBA 14 11-15-2016 01:42 AM
Help with Macro to Save Word File as PDF in Specific Location Macro: How to get this macro to save to a specific location LOUF Word VBA 1 12-07-2015 06:47 PM
How do I save a Word file with a macro for distribution? leemoreau Word VBA 3 10-04-2013 08:06 AM
Help with Macro to Save Word File as PDF in Specific Location A newbie question: a must to save macro word file as .docm? tinfanide Word VBA 6 12-06-2011 03:02 PM
Help with Macro to Save Word File as PDF in Specific Location Word Macro: Save file as text with current file name jabberwocky12 Word VBA 2 10-22-2010 12:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:01 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