Microsoft Office Field Code regex on filename?

0

Is it possible to filter the filename of the Word file to present it inside the document? Let's say I have the following filename: Acme Co - Project XYZ - Code #123 - Year 15.docx

I need to get Acme Co on the footer, Project XYZ on the cover title, Code #123 and Year 15 on the cover as subtitle items. I tried the fieldcode { FILENAME } but it only returns the entire filename and I didn't find any option regarding regex or filtering for that.

JChris

Posted 2015-12-14T02:28:03.917

Reputation: 203

Answers

1

Unfortunately, there is nothing in the "field code language" that will let you split up the result of a field code in this way. Well, except that in certain circumstances, you could just about use a DATABASE field to do it, but that is likely to cause a lot more trouble than it is worth.

That means that you really have to do some coding, e.g. in VBA, to do this. That usually means that you have to consider

  • that the user needs to know how, and when, to run the VBA (e.g. if they "Save As" under a different file name)
  • exactly how to ensure that all the segments are updated correctly, wherever they may be. If you can be sure that you are using Windows Word 2007 or later, you may be able to use Content Controls connected to an XML Custom Part to do that.

user181946

Posted 2015-12-14T02:28:03.917

Reputation:

Wow, that's a lot of trouble. In fact, this isn't for anything large scale and/or business related, it's for my own purposes, I'm an university student and I have to do some works periodically for a bunch of different classes, hence I'd like to automate the document title/footer/etc according to the file name. Regarding Office, I always use Office Pro Plus 2016. – JChris – 2015-12-14T20:20:05.633

Just my opinion, but I think kill you would be better off decoupling these bits of information from the file name and avoid having to do VBA code. E.g., create an old-style custom document property for each item you want to insert, use { DOCPROPEr – None – 2015-12-14T20:40:17.783

Sorry, editing in a poor environment here and ran out of time: use the built-in custom document property dialog to maintain your property values, then use { DOCPROPERTY } fields to insert the values where you need them. For each new document, you will need to modify the values, then locate all the fields and update their results. There is an alternative if you have a SharePoint account and the privileges necessary to create your own SharePoint document library with custom columns. – None – 2015-12-14T20:51:52.583

Thanks, I already use that to update the variables within the document. What I was looking for is something like creating in advance a bunch of docx files named Juan - Class XYZ - Work #XX - Issue #XX, and put the information that I already know about them, like Work #01, #02, ... #10 and the issue, Issue #01 or #02. This way I'd have all docx files already set up in the respective folders, leaving me free to just open them and start writing without worry. But it seems it isn't possible, and if it's, it would be more work than it's worth :) – JChris – 2015-12-14T23:18:27.917

If you can already write VBA, you may be able to write a routine that will generate the texts, generate the file name from that, create the file, create and populate the Custom Document Properties and update them. It's trying to take the file name and split it up using field codes that's not feasible. – None – 2015-12-15T10:11:38.273

Yeah, I see, many thanks. I'll try to have a look on VBA, after all, sooner or later I'll have to use it. – JChris – 2015-12-15T15:05:43.437