Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 06-06-2023, 09:12 AM
mery mery is offline Saving as a pdf file based on certain parameters in the document Windows 10 Saving as a pdf file based on certain parameters in the document Office 2013
Novice
Saving as a pdf file based on certain parameters in the document
 
Join Date: Jun 2023
Posts: 2
mery is on a distinguished road
Default

Solved
Code:
Sub sample2()


Dim srchRng As Range
Dim a As String, b As String, c As String

Set srchRng = ActiveDocument.Content


With srchRng.Find
    .Text = "ID:"
    .Execute
    If .Found = True Then
        Dim numberstart As Long
        numberstart = Len(srchRng.Text) + 1
        srchRng.MoveEndUntil Cset:=","

        Dim mynum As String
        mynum = Mid(srchRng.Text, numberstart)
    End If
End With
c = mynum

For nSectionNum = 1 To ActiveDocument.Sections.Count
Selection.GoTo What:=wdGoToSection, Which:=wdGoToNext, Name:=nSectionNum
ActiveDocument.Sections(nSectionNum).Range.Copy
     

Next nSectionNum
  

Dim oRng As Range
Dim oPara As Paragraph
Dim b As String, a As String

Set oPara = ActiveDocument.Paragraphs(5)
Set oRng = oPara.Range
oRng.End = oRng.End - 1
b = oRng.Text

Set oPara = ActiveDocument.Paragraphs(2)
Set oRng = oPara.Range
oRng.End = oRng.End - 1
a = oRng.Text

  
ActiveDocument.ExportAsFixedFormat OutputFileName:="E:\test\" & b & " " & a & " " & "Sample" & "" & c & ".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



End Sub
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to create document that will auto insert text based on parameters parisfranco Word 13 07-25-2017 03:21 PM
How to pass parameters to a .msg file? HereNow Outlook 0 11-05-2012 10:38 AM
Saving a contacts view parameters markjl Outlook 0 01-26-2011 04:19 AM
Update Document Template when Saving the Document File bjbercaw Word 3 11-16-2010 02:03 PM
Saving Word document creates a duplicate transparent file bbailey Word 0 12-05-2009 10:54 PM

Other Forums: Access Forums

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


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