![]() |
|
|
|
#1
|
|||
|
|||
|
I have a word file that reference number depend on filename.
Reference number format: RS-A589-STIS-00001-CV-00 Filename format: 00001-STIS-CV-00 The problem is when i used insert-quick parts-field-filename it will show this 00001-STIS-CV-00 what i what is this format RS-A589-STIS-00001-CV-00. Is this possible? Thank you! |
|
#2
|
||||
|
||||
|
How about the following. Display varRef with a docvariable field.
Code:
Dim strRef As String
Dim vRef As Variant
With ActiveDocument
strRef = Left(.Name, InStrRev(.Name, ".") - 1)
vRef = Split(strRef, "-")
strRef = "RS-A589-" & vRef(1) & "-" & vRef(0) & "-" & vRef(2) & "-" & vRef(3)
.Variables("varRef").Value = strRef
.Fields.Update
End With
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Thank you for your reply
how can i put this formula? I will make AutoOpen then insert your formula? how can i call it in the word file? I figured it already and it works like a charm... Thank you very much |
|
#4
|
|||
|
|||
|
hi gmayor,
is there a way of inserting certain filename in word? Example: KR-A359-STR-AA-00001-SHT 01 OF 01-00 What i want is only the STR-AA-00001-SHT 01 OF 01 or SHT 01 OF 01 or 00 Thank you |
|
#5
|
|||
|
|||
|
Hi gmayor
I figure it already but the problem is when i save as and change the filename its not updating. This the code I used: Code:
Sub AutoOpen()
Dim strRef, strDisp, strSht, strRev As String
Dim vRef, vDisp, vSht, vRev As Variant
With ActiveDocument
strRef = Left(.Name, InStrRev(.Name, ".") - 1)
vRef = Split(strRef, "-")
strRef = "KR-A359-STR-" & vRef(1) & "-" & vRef(2) & "-" & vRef(3) & "-" & vRef(4)
.Variables("varRef").Value = strRef
.Fields.Update
End With
With ActiveDocument
strDisp = Left(.Name, InStrRev(.Name, ".") - 1)
vDisp = Split(strDisp, "-")
strDisp = "KR-A359-STR-" & vDisp(1)
.Variables("varDisp").Value = strDisp
.Fields.Update
End With
With ActiveDocument
strSht = Left(.Name, InStrRev(.Name, ".") - 1)
vSht = Split(strSht, "-")
strSht = vSht(3) & "-" & vSht(4)
.Variables("varSht").Value = strSht
.Fields.Update
End With
With ActiveDocument
strRev = Left(.Name, InStrRev(.Name, ".") - 1)
vRev = Split(strRev, "-")
strRev = "STR-" & vRev(1) & "-" & vRev(2) & "-" & vRev(3)
.Variables("varRev").Value = strRev
.Fields.Update
End With
End Sub
|
|
#6
|
||||
|
||||
|
I am no longer sure what it is that you are trying to do. Earlier you said the filename was
00001-STIS-CV-00 That being the case your code cannot possibly work e.g. Take the line Code:
strRef = "KR-A359-STR-" & vRef(1) & "-" & vRef(2) & "-" & vRef(3) & "-" & vRef(4) Code:
strRef = "KR-A359-STR-" & vRef(0) & "-" & vRef(1) & "-" & vRef(2) & "-" & vRef(3) vRef(1) is STIS vRef(2) is CV vRef(3) is 00
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#7
|
|||
|
|||
|
Sorry about that the reference and code is working except when save as for new document. This different but i think the code is the same. Im trying to use in my other form the Filename for that is
KR-A359-STR-00001-SHT 01 OF 01-00 and i need to extract that filename into four groups. 1. STR-00001-SHT 01 OF 01-00 2. KR-A359-STR- 3. SHT 01 OF 01 4. 00 and the code i used is the one i post but there is a problem whenever i save as for a new document and change the filename it will not reflect automatically in the new document. Thank you for your reply. |
|
#8
|
||||
|
||||
|
I still have no idea what it is that you are trying to do but if you are trying to split
KR-A359-STR-00001-SHT 01 OF 01-00 at the hyphens, there are four elements (0 to 3 not 1 to 4) If you are trying to display the filename in a filename field then you need to update the field after saving the document then save that change.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#9
|
|||
|
|||
|
what do you mean by "update the field after saving the document then save that change"
I will make another declaration or is there a additional code? Thank you |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to insert Wildcards into Word 2011 Mac such as: \$Filename\
|
peterspiano | Word | 4 | 06-29-2015 05:13 AM |
| Excel connot open file (filename) xlsx | dengeorge6 | Excel | 0 | 12-12-2014 01:36 AM |
A macro that can insert FILENAME, sendkeys CTRL ALT T, paste clipboard, and nextline
|
kyjac85 | Word VBA | 13 | 09-20-2012 05:00 PM |
How to insert current date into default filename ?
|
czomberzdaniela | Word | 1 | 12-27-2011 07:18 PM |
| Macro for automatically adding filename without .doc | RPM7 | Word VBA | 0 | 04-29-2010 01:43 AM |