Microsoft Office Forums Macro to save as pdf with ability to choose save as folder

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-30-2011, 11:54 AM
rvessio rvessio is offline Macro to save as pdf with ability to choose save as folder Windows 7 32bit Macro to save as pdf with ability to choose save as folder Office 2010 32bit
Novice
Macro to save as pdf with ability to choose save as folder
 
Join Date: May 2011
Posts: 2
rvessio is on a distinguished road
Default Macro to save as pdf with ability to choose save as folder

I was lucky enough to come across this macro on this forum to save as pdf but I need to alter a bit so that it allows the user to select the folder to save it in. Any ideas?

With ActiveDocument
.ExportAsFixedFormat OutputFileName:=Split(.FullName, ".")(0) & ".pdf", _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _


OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End With

Thanks!
Reply With Quote
  #2  
Old 05-31-2011, 02:36 AM
macropod's Avatar
macropod macropod is offline Macro to save as pdf with ability to choose save as folder Windows 7 32bit Macro to save as pdf with ability to choose save as folder Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,525
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Hi rvessio,

Try:
Code:
Sub SaveToPDF()
With ActiveDocument
  .ExportAsFixedFormat OutputFileName:=GetFolder & "\" & Split(.Name, ".")(0) & ".pdf", _
  ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
  OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
  Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
  CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
  BitmapMissingFonts:=True, UseISO19005_1:=False
End With
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 06-02-2011, 07:17 AM
rvessio rvessio is offline Macro to save as pdf with ability to choose save as folder Windows 7 32bit Macro to save as pdf with ability to choose save as folder Office 2010 32bit
Novice
Macro to save as pdf with ability to choose save as folder
 
Join Date: May 2011
Posts: 2
rvessio is on a distinguished road
Default

Thanks that worked, the only thing is that if a file already exists with the same name it doesn't prompt to overwrite.
Reply With Quote
  #4  
Old 06-02-2011, 02:42 PM
macropod's Avatar
macropod macropod is offline Macro to save as pdf with ability to choose save as folder Windows 7 32bit Macro to save as pdf with ability to choose save as folder Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,525
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Hi rvessio,

It would have been nice if you'd said you needed to check before overwriting. Try this variation:
Code:
Sub SaveToPDF()
Dim StrPath As String, StrName As String, Result
With ActiveDocument
  On Error GoTo Errhandler
  StrPath = GetFolder & "\"
  StrName = Split(.Name, ".")(0)
  While Dir(StrPath & StrName & ".pdf") <> ""
    Result = InputBox("WARNING - A file already exists with the name:" & vbCr & _
      Split(.Name, ".")(0) & vbCr & _
      "You may edit the filename or continue without editing." _
      & vbCr & vbTab & vbTab & vbTab & "Proceed?", "File Exists", StrName)
    If Result = vbCancel Then Exit Sub
    If StrName = Result Then GoTo Overwrite
    StrName = Result
  Wend
Overwrite:
  .ExportAsFixedFormat OutputFileName:=StrPath & StrName & ".pdf", _
  ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
  OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
  Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
  CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
  BitmapMissingFonts:=True, UseISO19005_1:=False
End With
Errhandler:
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 07-25-2016, 12:37 PM
JulieMcD240 JulieMcD240 is offline Macro to save as pdf with ability to choose save as folder Windows 8 Macro to save as pdf with ability to choose save as folder Office 2010 64bit
Novice
 
Join Date: Jul 2016
Location: Virginia Beach, VA
Posts: 1
JulieMcD240 is on a distinguished road
Default Add pdf to email

Hello,

I found this code in the thread below very useful but would like to take it one step further. After the pdf is created, I would like to add it to an Outlook email and distribute it.

Any help would be great. Thanks!

Julie

Sub SaveToPDF()
Dim StrPath As String, StrName As String, Result
With ActiveDocument
On Error GoTo Errhandler
StrPath = GetFolder & "\"
StrName = Split(.Name, ".")(0)
While Dir(StrPath & StrName & ".pdf") <> ""
Result = InputBox("WARNING - A file already exists with the name:" & vbCr & _
Split(.Name, ".")(0) & vbCr & _
"You may edit the filename or continue without editing." _
& vbCr & vbTab & vbTab & vbTab & "Proceed?", "File Exists", StrName)
If Result = vbCancel Then Exit Sub
If StrName = Result Then GoTo Overwrite
StrName = Result
Wend
Overwrite:
.ExportAsFixedFormat OutputFileName:=StrPath & StrName & ".pdf", _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End With
Errhandler:
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder( 0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to save as pdf with ability to choose save as folder Macro to save as PDF but with a different name shabbaranks Word VBA 2 05-20-2011 01:02 AM
Macro to Save Help clarkson001 Word 0 02-14-2011 06:41 AM
Does not SAVE AS to default folder pleveque Office 0 01-13-2011 08:34 AM
Macro Won't Save lou0915 Word VBA 2 10-17-2009 08:13 PM
How can I save multiple email messages to a file folder? (crosspost) tupham Outlook 0 08-04-2008 07:56 PM


All times are GMT -7. The time now is 01:28 PM.


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