#1
|
|||
|
|||
How to save Word file by field name as filename using VBA button?
For example I need to save a Word doc by Costumer Number (example; David Hass) and Request Number (example: 001-17) so when I click on VBA button Save by CN & RN, my Word file should be saved on PDF format in the same folder by name David Hass 001-17.
|
#2
|
|||
|
|||
I'm assuming you already know to create a userform with the button. In order to get the "constumer number" and "request number", we need to know where those are generating in your document in order to define the range. Does the "constumer number" and "request number" always generate in the same spot?
|
#3
|
|||
|
|||
Dear dwirony,
I know hot to create a Form but I don't know how to create the VBA button. And yes, "constumer number" and "request number" always are in the same spot? Thank you so much |
#4
|
|||
|
|||
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 |
#5
|
|||
|
|||
sample document
Dear dwirony
|
#6
|
|||
|
|||
Oh, I was under the impression that you were working from a Microsoft Word document, not excel. I'm afraid I can't help you if you're working out of excel. You're best off cross posting this over to an excel forum.
|
|
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 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 |
Auto update Filename field | Oliver Beirne | Word VBA | 4 | 10-19-2012 03:33 AM |
Save Filename using Document Text | Knawl | Word | 11 | 10-10-2011 03:00 AM |