Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 04-07-2016, 09:32 PM
gmayor's Avatar
gmayor gmayor is offline Naming Documents From Populated Cells Windows 10 Naming Documents From Populated Cells Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The function I posted would not be listed in macros as it is intended to be called from either another macro or the process in the link.

The process can work with individual documents, but it is an overhead that would irritate for your regular work pattern. I included it to increase traffic to my web site, which provides a small income to help justify the time spent in these forums, and of course if you were processing large numbers of documents, it works well to handle the folders where the documents are saved.

As I suggested, it can easily be modified to work as a stand alone macro (see below) to extract the required contents of the table. However having seen your sample document, it has an extra row at the top, which does not appear in your illustration, so the row count needs to be incremented by one, to read the required cells.
Code:
Sub RenameDoc()
Dim oDoc As Document
Dim oTable As Table
Dim oCell As Range
Dim sFname As String
Const sPath As String = "C:\Path\"    'the path to save the documents
    On Error GoTo err_Handler
    Set oDoc = ActiveDocument
    Set oTable = oDoc.Tables(1)
    Set oCell = oTable.Rows(7).Cells(3).Range
    oCell.End = oCell.End - 1
    sFname = oCell.Text & Chr(32)
    Set oCell = oTable.Rows(5).Cells(1).Range
    oCell.End = oCell.End - 1
    sFname = sFname & oCell.Text & Chr(32)
    Set oCell = oTable.Rows(3).Cells(1).Range
    oCell.End = oCell.End - 1
    sFname = sPath & sFname & oCell.Text & ".docx"
    oDoc.SaveAs2 Filename:=sFname, Addtorecentfiles:=False
lbl_Exit:
    Exit Sub
err_Handler:
    Err.Clear
    GoTo lbl_Exit
End Sub
Paul's macro does much the same but uses a different method to extract the data from the cells. I'll leave it to you to decide which is the easier to comprehend.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
macro, naming



Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch re-naming twols26 Word VBA 7 06-16-2015 12:29 PM
Naming Cells for formula referencing lynchbro Excel 6 06-26-2014 07:45 AM
Please Help! Need auto populated last saved date. Neveradayoff Excel 0 02-05-2014 09:42 AM
Naming Documents From Populated Cells Drop-down Populated with text entry ReviTULize Word VBA 14 02-21-2013 07:06 PM
Naming Documents From Populated Cells Request: Creating an Auto-Populated Template Skep18 Word 2 05-29-2012 10:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:07 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