![]() |
|
#1
|
||||
|
||||
![]()
Used in conjunction with the following to handle the folders,
http://www.gmayor.com/document_batch_processes.htm
though easily modified to work as a stand alone macro to process a single document, the following function will extract the required data from a table that matches the illustration and save the document with the filename extracted. It assumes none of the documents will have illegal filename characters in the cells (the sample doesn't) and you will have to add the path where you want to save the documents (which must exist). Code:
Option Explicit Function RenameDoc(oDoc As Document) As Boolean 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 oTable = oDoc.Tables(1) Set oCell = oTable.Rows(6).Cells(3).Range oCell.End = oCell.End - 1 sFname = oCell.Text & Chr(32) Set oCell = oTable.Rows(4).Cells(1).Range oCell.End = oCell.End - 1 sFname = sFname & oCell.Text & Chr(32) Set oCell = oTable.Rows(2).Cells(1).Range oCell.End = oCell.End - 1 sFname = sPath & sFname & oCell.Text & ".docx" oDoc.SaveAs2 Filename:=sFname, Addtorecentfiles:=False RenameDoc = True lbl_Exit: Exit Function err_Handler: RenameDoc = False Resume lbl_Exit End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#2
|
|||
|
|||
![]()
gmayor: Thanks for your reply and the code you provided. However, I can't seem to make heads or tails of it. Sadly I'm not very experienced in VBA. It doesn't show up in my Macros listings. I tried adding it to an existing Macro, as well as enclose it with Sub ReName(), but that didn't work.
My apologies, I'm a little out of my depth. As you mentioned in your post, this would need to work as a stand alone macro to process a single document. Basically I download the .docx from a central server, open it up, edit it slightly, rename it, and pass it along. I do this probably 50 times a day, which is why having this kind of a naming Macro would be a big time saver for me. |
![]() |
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 |