![]() |
#1
|
|||
|
|||
![]()
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 |
#2
|
||||
|
||||
![]()
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 |
#3
|
|||
|
|||
![]()
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 |
#4
|
||||
|
||||
![]()
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 |
![]() |
Tags |
bookmarks, macro in word, save as pdf |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
youseeme | Word VBA | 9 | 09-16-2016 05:25 AM |
![]() |
tomsrv | Word VBA | 13 | 08-24-2016 02:26 AM |
![]() |
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 |
![]() |
xscotsmanx | Word VBA | 1 | 07-17-2011 12:23 AM |