Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-05-2017, 09:18 AM
pamtupac pamtupac is offline macro to save as pdf with name from bookmark Windows 10 macro to save as pdf with name from bookmark Office 2016
Novice
macro to save as pdf with name from bookmark
 
Join Date: Jun 2017
Posts: 2
pamtupac is on a distinguished road
Default macro to save as pdf with name from bookmark

hi all,



i'm trying to create a command button in word and attach a macro that automatically saves the doc as a pdf to a specified folder with file with the name coming from 2 bookmark references with a space and dash in between name.

here is what i have so far:

Private Sub CommandButton1_Click()

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Users\sesa460426\Box Sync\My Projects\Quotes" & ClientName = .Bookmarks("ClientName").Range.Text&.Bookmarks("Qu oteNumber").Range.Text & (".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
ChangeFileOpenDirectory "C:\Users\sesa460426\Box Sync\My Projects\Quotes"
End Sub


i keep getting an invalid or unqualified reference error and it highlights the .bookmarks part. i'm very very new to vba so if someone can please help me.

ps. i've also tried adding activedocument before the .bookmarks part but then i get a different error.

thanks in advance
Reply With Quote
  #2  
Old 06-05-2017, 09:52 PM
gmayor's Avatar
gmayor gmayor is offline macro to save as pdf with name from bookmark Windows 10 macro to save as pdf with name from bookmark Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

Assuming the named folder exists and the bookmarks both exist and have content and there are no illegal filename characters in either bookmark (all of which should really be error trapped) then:

Code:
Private Sub CommandButton1_Click()
Const strPath As String = "C:\Users\sesa460426\Box Sync\My Projects\Quotes\"
Dim strName As String
    On Error Resume Next
    strName = ActiveDocument.Bookmarks("ClientName").Range.Text
    strName = strName & ActiveDocument.Bookmarks("QuoteNumber").Range.Text
    If Not strName = "" Then
        strName = strName & ".pdf"
        ActiveDocument.ExportAsFixedFormat OutputFileName:= _
                                           strPath & strName, _
                                           ExportFormat:=wdExportFormatPDF, _
                                           OpenAfterExport:=False, _
                                           OptimizeFor:=wdExportOptimizeForPrint, _
                                           Range:=wdExportAllDocument, _
                                           From:=1, to:=1, _
                                           Item:=wdExportDocumentContent, _
                                           IncludeDocProps:=True, _
                                           KeepIRM:=True, _
                                           CreateBookmarks:=wdExportCreateNoBookmarks, _
                                           DocStructureTags:=True, _
                                           BitmapMissingFonts:=True, _
                                           UseISO19005_1:=False
    End If
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
  #3  
Old 06-06-2017, 09:17 AM
pamtupac pamtupac is offline macro to save as pdf with name from bookmark Windows 10 macro to save as pdf with name from bookmark Office 2016
Novice
macro to save as pdf with name from bookmark
 
Join Date: Jun 2017
Posts: 2
pamtupac is on a distinguished road
Default

thanks graham but it's not outputting anything i took out the if statement and i got name not valid error. i'm looking for a workaround as i need the name to be the hyperlink values from excel. i posted in the other forum for help with greg if you want to see it and want to help me. sorry about double posting i just wasn't getting any answers >.<

http://www.vbaexpress.com/forum/show...620#post362620
Reply With Quote
  #4  
Old 06-06-2017, 08:23 PM
gmayor's Avatar
gmayor gmayor is offline macro to save as pdf with name from bookmark Windows 10 macro to save as pdf with name from bookmark Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

Read the sentence above the code and check what you have in your document.
__________________
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

Tags
bookmarks, macro in word, save as pdf

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to save as pdf with name from bookmark Macro to Insert Logo in header on 1st page only and bookmark it. youseeme Word VBA 9 09-16-2016 05:25 AM
macro to save as pdf with name from bookmark Macro to return a word count of text contained within a bookmark tomsrv Word VBA 13 08-24-2016 02:26 AM
macro to save as pdf with name from bookmark Macro to save as pdf with ability to choose save as folder rvessio Word VBA 4 07-25-2016 12:37 PM
Find Bookmark, move to bookmark, execute code, repeat raymm3852 Word VBA 10 04-15-2016 06:21 PM
macro to save as pdf with name from bookmark Default Save AS File Name from Bookmark xscotsmanx Word VBA 1 07-17-2011 12:23 AM

Other Forums: Access Forums

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


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