Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2017, 04:43 AM
chemtoli chemtoli is offline How to save Word file by field name as filename using VBA button? Windows 7 32bit How to save Word file by field name as filename using VBA button? Office 2007
Novice
How to save Word file by field name as filename using VBA button?
 
Join Date: Jan 2017
Posts: 5
chemtoli is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 01-20-2017, 09:08 AM
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

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?
Reply With Quote
  #3  
Old 01-21-2017, 05:20 AM
chemtoli chemtoli is offline How to save Word file by field name as filename using VBA button? Windows 7 32bit How to save Word file by field name as filename using VBA button? Office 2007
Novice
How to save Word file by field name as filename using VBA button?
 
Join Date: Jan 2017
Posts: 5
chemtoli is on a distinguished road
Default

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
Reply With Quote
  #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
  #5  
Old 01-24-2017, 08:36 AM
chemtoli chemtoli is offline How to save Word file by field name as filename using VBA button? Windows 7 32bit How to save Word file by field name as filename using VBA button? Office 2007
Novice
How to save Word file by field name as filename using VBA button?
 
Join Date: Jan 2017
Posts: 5
chemtoli is on a distinguished road
Default sample document

Dear dwirony
Attached Files
File Type: xlsx David Hass 001-17.xlsx (12.2 KB, 11 views)
Reply With Quote
  #6  
Old 01-25-2017, 08:06 AM
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

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.
Reply With Quote
Reply



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 12:56 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