Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi,

    I'm creating a template where I need to show only part of the filename and path field. The filename is a document number and the path always contains a reference to one of four databases (let's say I have Adatabase, Bdatabase, Cdatabase and Ddatabase). My problem is that the same document number could exist in all four databases, hence I need to extract the first letter of the database name and show that before the filename portion of the field.

    The full filename and path generally shows as:

    C:\nrportbl\Adatabase\username\1234567.doc

    All I want to show (in the footer) is "A1234567.doc". Can anyone help?

    Thanks,

    Violet

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Will the "database" part always be the same? I.e. could we look for the string "database" in the path?

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Hans, no longer receive error, outwith lo-fi!

    I am now a bit further forward thanks to Stuart's post. We are now going to put the following code into a clsEvent in normal dot and the code I am now working with is:

    Dim footertext, dbaseletter As String
    Dim dbasepos As Integer
    If InStr(0, ActiveDocument.AttachedTemplate, "letter") > 0 Then
    footertext = ActiveDocument.FullName
    dbasepos = InStr(1, footertext, "imanage") - 1
    dbaseletter = UCase(Mid(footertext, 13, 1))
    footertext = dbaseletter & ActiveDocument.Name
    MsgBox footertext
    End If

    So what I need to work out next is:

    if a user generates a new document based on any of our letter templates, how do I ensure the "footertext" is inserted (it will have to insert at a bookmark because it needs to appear in the footer after some other text that must always appear for legal reasons)?

    and

    I also to make sure that if the "footertext" is already present at the bookmark, then nothing happens.

    I would normally tinker about myself for a while until I got some results but unfortunately time is of the essence on this one because of deadlines.

    Thanks!

    Violet

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Would it be feasible to regenerate the entire footer text, not just the filename part? That way you wouldn't have to worry about whether the text has already been added or not.

  5. #5
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry Hans, I'm not really sure what you're asking but I think I've confused matters talking about that I want to insert and what is already there, so a copy of a template of ours is attached. In the footer of all of our letters, we have a disclaimer and on the line underneath there is a bookmark which is where we want our "footertext" to appear.

    I should also mention we are adding our little bit of "footertext" code into a clsEvent that already exists in normal.dot as follows:

    Public WithEvents app As Application

    Private Sub app_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)
    Dim aStory As Range
    Dim aField As Field
    On Error Resume Next
    For Each aStory In Doc.StoryRanges
    For Each aField In aStory.Fields
    If aField.Type = wdFieldFileName Then
    aField.Update
    End If
    Next aField
    Next aStory
    Set aField = Nothing
    Set aStory = Nothing
    End Sub

    My boss pointed out that if a user re-opens a saved letter where "footertext" already exists then we don't want anything to happen. Am I just muddying the waters further here (this is all way over my head, I'm very confused, sorry).

    Thanks,

    Violet
    Attached Files Attached Files

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Violet, is it an option to do the following:

    In your template, use a text placeholder for the file name, such as *CalcFilename* and have your procedure look for this placeholder and, if it's found, and if the file has been saved (so a path exists), replace it with the the text you want?

    This would resolve the issue of having the field updated time and time again whenever the document is re-opened. On the other hand, if the user uses Save As, rather than creating a new document from the template, then the footer information would have to be manually updated (or, more likely, the mismatch would not be noticed).

  7. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi Violet,

    Here's a Word macro showing how I might approach the task, based on the use of a bookmark in the footer, named "FootMark":
    [codebox]Sub MakeDBFileRef()
    Dim i As Integer
    Dim Prefix As String
    Dim BmkNm As String
    Dim BmkRng As Range
    With ActiveDocument
    BmkNm = "FootMark"
    For i = 1 To UBound(Split(.Path, "\"))
    If InStr(Split(.Path, "\")(i), "database") > 0 Then _
    Prefix = Replace(Split(.Path, "\")(i), "database", "")
    Next
    If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    BmkRng.Text = Prefix
    .Bookmarks.Add BmkNm, BmkRng
    End If
    End With
    End Sub
    [/codebox]
    If you insert the bookmark immediately before a standard FILENAME field (ie without the \p to generate the path), the macro would only ever need to be run once, via an AutoNew macro in your document template (unless the db prefix changes).
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  8. #8
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks to all, as ever, for your input. We ended up with the following in a clsEvent within normal.dot:

    Public WithEvents app As Application

    Private Sub app_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)
    Dim aStory, BMRange As Range
    Dim aField As Field
    Dim footertext, dbaseletter As String
    Dim dbasepos, letterpos, memopos, faxpos As Integer
    On Error Resume Next
    For Each aStory In Doc.StoryRanges
    For Each aField In aStory.Fields
    If aField.Type = wdFieldFileName Then
    aField.Update
    End If
    Next aField
    Next aStory
    Set aField = Nothing
    Set aStory = Nothing
    'insert filename text
    letterpos = InStr(1, ActiveDocument.AttachedTemplate, "letter")
    faxpos = InStr(1, ActiveDocument.AttachedTemplate, "fax")
    memopos = InStr(1, ActiveDocument.AttachedTemplate, "memo")
    Set BMRange = ActiveDocument.Bookmarks("docnum").Range
    If letterpos Or faxpos Or memopos > 0 Then
    footertext = ActiveDocument.FullName
    dbasepos = InStr(1, footertext, "imanage") - 1
    dbaseletter = UCase(Mid(footertext, 13, 1))
    footertext = dbaseletter & ActiveDocument.name
    BMRange.Text = footertext
    ActiveDocument.Bookmarks.Add "docnum", BMRange
    End If
    End Sub


    Now I'm trying to figure out where to put activedocument.reload so the user doesn't have to refresh the screen manually!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •