Last 3 characters before .doc in field

B

Brian

Good morning all,

I have got myself in a thought loop. What I am trying to achieve, is create
a field reference to a macro. The macro will identify the last 3 characters
in the file name, prior to the .doc extention.

The file names including the path are not consistent in length.

The idea is when the document is saved with a new version number, the
document will be updated with the new version number in the all footers and
other reference points within the document i.e., Version {field macro return}.

I have been adapting the following to try to achieve this with no luck. Any
guidance would be gratefully received.

Sub insertVno()
Dim fname As String
Dim strTemp() As String
With ActiveDocument
fname = .Name
strTemp = Split(fname, ".") & strTemp
sstrTemp = strTemp
pInputStr() = Split(".Name, "\")

fname = sstrTemp(3) & "." & strTemp(4)
.Variables("varVERFilename").Value = fname
.PrintPreview
.ClosePrintPreview
End With
' End Sub

Thanks
 
B

Brian

Thanks for the response Doug.

Not quite what I had in mind.

In the sets of documents, when I have prepared it to the next stage in the
process, V0.1 fo initial, V0.2 for 1st draft, etc. There may be many saves in
between. And sometimes, it may be up-versioned more than once a day.

When I save the file withe the new version number, i.e., B&H_RMM_NDC_Return
to Supplier_V0.2.doc I would like the field to be updated with the characters
"0.2" only.

Thanks for your response.
 
D

Doug Robbins - Word MVP

Use a { DOCVARIABLE varVersion } field where you want the information to
appear and then use the following code

Dim DocName As String
With ActiveDocument
DocName = .Name
.Variables("varVersion").Value = Mid(DocName, InStr(DocName, "_V") + 2,
3)
.Range.Fields.Update
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Brian

Doug,

Many thanks. I think I was making things too complicated for myself.

Works fine. Now I am working on trying to hijack the SaveAs function so I
don't have to close and re-open the file for the update. Tried a few things
commented out in the code.

Sub insertVno()
Dim DocName As String
'Sub FileSaveAs()
'If FileSaveAs = True Then
'Dialogs(wdDialogFileSaveAs).Show
With ActiveDocument
DocName = .Name
.Variables("varVersion").Value = Mid(DocName, InStr(DocName, "_V") + 2, 3)
.Range.Fields.Update
End With
'ActiveDocument.Save
'End If
End Sub

I'll get there in the end .

Thanks again for your help.

Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top