Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 01-23-2017, 02:19 PM
dwirony dwirony is offline How to save Word file by field name as filename using VBA button? Windows 7 64bit How to save Word file by field name as filename using VBA button? Office 2003
Advanced Beginner
 
Join Date: Oct 2016
Posts: 49
dwirony will become famous soon enough
Default

Could you provide a sample document? I need to see where the variables generate so we can create a range. For example, lets just say this is a line in your document:

"Dear customer: Your constumer number is 21523. Please refer to your request number which is 02915. These numbers will assist you in..."

Then we would use a range function like this to give a value to those:

Code:
Dim rng1 As Range, rng2 As Range, ConstumerNumber As String, RequestNumber As String
    Set rng1 = ActiveDocument.Range
    If rng1.Find.Execute(FindText:="Your constumer number is ") Then
            Set rng2 = ActiveDocument.Range(rng1.End, ActiveDocument.Range.End)
            If rng2.Find.Execute(FindText:=". Please refer to your") Then
                ConstumerNumber = ActiveDocument.Range(rng1.End, rng2.Start).Text
            End If
    End If
    Set rng1 = ActiveDocument.Range
    If rng1.Find.Execute(FindText:="request number which is ") Then
            Set rng2 = ActiveDocument.Range(rng1.End, ActiveDocument.Range.End)
            If rng2.Find.Execute(FindText:=". These numbers will assist") Then
                RequestNumber = ActiveDocument.Range(rng1.End, rng2.Start).Text
            End If
    End If
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to save Excel file by field name as filename chemtoli Excel 4 01-22-2017 08:32 AM
How to save Word file by field name as filename using VBA button? How can I save a Word Document as a PDF file with a merged field filename? kp2009 Word VBA 5 08-27-2015 11:45 PM
Save Filename based on Text Field madcar86 Word VBA 8 10-19-2014 12:53 AM
How to save Word file by field name as filename using VBA button? Auto update Filename field Oliver Beirne Word VBA 4 10-19-2012 03:33 AM
How to save Word file by field name as filename using VBA button? Save Filename using Document Text Knawl Word 11 10-10-2011 03:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:06 AM.


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