Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2016, 09:02 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,143
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

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
Reply With Quote
  #2  
Old 04-07-2016, 07:43 AM
TYPOGRAPHICS TYPOGRAPHICS is offline Naming Documents From Populated Cells Windows 7 64bit Naming Documents From Populated Cells Office 2010 64bit
Novice
Naming Documents From Populated Cells
 
Join Date: Apr 2016
Posts: 4
TYPOGRAPHICS is on a distinguished road
Default Gmayor

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

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 04:21 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