![]() |
#7
|
||||
|
||||
![]()
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
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
macro, naming |
|
![]() |
||||
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 |
![]() |
ReviTULize | Word VBA | 14 | 02-21-2013 07:06 PM |
![]() |
Skep18 | Word | 2 | 05-29-2012 10:52 AM |