Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Retrieving an information from filename ...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jiří - 03 Jul 2007 10:12 GMT
Hallo,

I just solve the problem how to retrieve an information from filename string
to the fields (eg. doc number, author, revision etc.). File storage system
works automatically and the export from repository generate the filename in
following form:
<DOC_ID>_<DOC_REV>_<DOC_PROD>_<DOC_NAME>.ext

Each part of  this has defined length and it is possible to find exact index
possition of each substring. These strings may be then stored in specific
fields and (after update) printed with the document.

Any suggestions?

Thanks,
George
Jonathan West - 03 Jul 2007 12:21 GMT
> Hallo,
>
[quoted text clipped - 12 lines]
>
> Any suggestions?

Look up the following string handling functions in the VBA help

Split, Mid, Left, InStr, InStrRev, Right.

Between them, they provide all the tools you need for this task.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

David Sisson - 03 Jul 2007 15:43 GMT
I'm not sure if you are asking about how to parse filename or data, so
I'll take a stab at the filename.

Sub ParseFields2()
Dim MyString As String

MyString = "<DOC_ID>_<DOC_REV>_<DOC_PROD>_<DOC_NAME>.ext"

Field1$ = Mid(MyString, 2, 6)
Field2$ = Mid(MyString, 11, 7)
Field3$ = Mid(MyString, 21, 8)
Field4$ = Mid(MyString, 32, 8)

MsgBox (Field1$ & vbCr & Field2$ & vbCr & Field3$ & vbCr & Field4$)

End Sub

Or, this one is a little more dynamic.  If the field names change,
it'll still parse correctly. (Assuming the chevrons and underscores
don't change.)

Sub ParseFields()

Dim MyString As String
Dim MyArray() As String

MyString = "<DOC_ID>_<DOC_REV>_<DOC_PROD>_<DOC_NAME>.ext"
MyString = Mid(MyString, 2, InStr(MyString, ">.") - 2)
MyString = Replace(MyString, ">_<", ">=<")
MyArray = Split(MyString, ">=<")

MsgBox (MyArray(0) & vbCr & MyArray(1) & vbCr & MyArray(2) & vbCr &
MyArray(3))

End Sub
Graham Mayor - 03 Jul 2007 15:52 GMT
I rather suspect that the <> bracketed items are variables of unknown
length?

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> I'm not sure if you are asking about how to parse filename or data, so
> I'll take a stab at the filename.
[quoted text clipped - 31 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.