Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Star Lounger
    Join Date
    Jun 2001
    Location
    Brisbane Australia
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filename Field (Word 97)

    We use a standard document footer with the document name and full path in the left of the footer. we have some issues now as our project has been under way for some time and the length of the result [we are several folders down from the root of a shared network drive] is quite large.

    The standard Word option of "p" therefore isn't ideal. Is there any way to modify the results of the field such that it produces either a standard starting folder location [and any lower levels in the path] or possibly 1 or 2 levels above the current folder location?

    Thanks

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Filename Field (Word 97)

    John,

    If you're up to some VBA, I think there have been some solutions for similar items on the lounge. What I recall seeing were some procedures that examined the characters of the full path/file name looking for a slash starting from the right to get just the file name. In your case, one might look for, say, the 3rd slash from the right, which would give you 2 folders up. I'm not clear exactly which of your options you prefer. But how would you specify the standard starting folder location? This could be interactive (show the full path and ask you how many folders up or start at a specific folder and go all the way down) but that seems more trouble than it's worth.

    My Word VBA skills are somewhat limited. So let's see if others can help out.

    Without VBA, I think it would be a little harder.

    Fred

  3. #3
    Star Lounger
    Join Date
    Jun 2001
    Location
    Brisbane Australia
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Field (Word 97)

    Hi Fred

    I pretty much imagined that would be the way I would need to go. I've used an occasional macro and played with VBA in some of my Access databases but am really a novice here. If anyone can enlighten me how I can approach this task I would appreciate it.

    The folders I am talking about run G:Project OfficeProject Mirror...

    I really want to park "Project Mirror" as the highest level and report everything below that as the filename in the document footer. Where and how should I start with this please?

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Filename Field (Word 97)

    John,

    I should have asked more questions about your footers but here's something to get you started.

    <pre>Sub abbrevpath()
    Dim EntireName As String, ShortName As String
    EntireName = ActiveDocument.fullname
    ShortName = "G:..." & Mid(EntireName, 18)
    End Sub
    </pre>


    The above code will just pick up the full name of the active document (guess which statement that is). Based on what you told me (that all files will be on the G drive, you want to omit the "Project Office" folder but keep what comes starting from "Project Mirror" downward), the ShortName is developed. Given that the top part of the path is fixed and known, this is easier than I thought it could be.

    You also could have omitted the EntireName statement and just put
    ShortName = "G:..." & Mid(ActiveDocument.fullname, 18)

    The Mid function grabs off a set of characters from a given string (EntireName in this case) starting at a given point. If you only wanted to grab a certain number of characters, as opposed to all remaining, you'd put the number of characters as the 3rd argument to Mid.

    The & is the concatenation operator. Basically it creates a longer strong from 2 shorter ones. If you've done Access, you may have used this.

    It wasn't clear from your email whether you wanted "Project Mirror" included in the ShortName or what comes after that. I've assumed the former. If the latter, increase 18 to account for "Project Mirror" and maybe the slash after it. I've started the path with the slash but I hope you can see how to omit the slash if that's what you want.

    What the above will give you is the following
    G:...Project Mirrorxxxyyyzzz.ext
    or
    G:...Project Mirroraaabbb.ext

    I'm assuming you might want the G:... part. If not, just start the right side of the = for ShortName as Mid (that is, delete
    "G:..." &

    Lastly, for now, you can display what you have so far by adding a statement like
    MsgBox(ShortName)
    before the End Sub

    As for the footer issues (where I really might get lost):
    - do the documents only have 1 footer or are there many (more than 1 section, 1 section with different 1st page and/or different odd/even)?
    - if the document has more than 1 footer, are all the ones after the 1st linked to the first by using "Same as Previous"?
    - where exactly in the footer is the ShortName needed? left, center, right? are there multiple lines such that this should be on a particular line?
    - I'd assume, but I'll ask, that you want the ShortName to be formatted with the same font and point size as other items in the footer?

    I think that's about it. Give the above a shot. Maybe you can even get the ShortName into the footer.

    One other thing I'm assuming here is that you can get the above VBA into a macro. This is not something you can use the macro recorder for. But you can start recording a macro (giving your macro a name of "abbrevpath" when prompted or whatever you want) and then stop immediately. Go into the visual basic environment (press ALT+F11). You should be able to find the empty shell for the macro you just recorded pretty easily. Copy and paste the lines above (or however you've changed them) omitting the sub and the end sub lines (your recording will have provided those). The macro recording will also provide a few comments at the beginning - you can leave those as they are and paste the above below the last comment and above the end sub line.

    Hope this gets you started.

    Fred

  5. #5
    Star Lounger
    Join Date
    Jun 2001
    Location
    Brisbane Australia
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Field (Word 97)

    Thanks Fred.

    I can follow what you are saying and I can try that when I'm back into work tomorrow [home today].

    Generally all the docs will have common footers throughout so that shouldn't be a problem, and I can see ways that I can vary the code such that, if we send the document through e-mail to another area I can test the path and modify the abbreviation if it is no longer in the Project Mirror folder on G: drive.

    What I am missing though is how I get the code to execute in the footer. I can relate to putting "fields" in the footer - how does this VBA code execute there though? Do I have to include some kind of "execute statement" or something where I would normally place the field "FILENAME"? This is something I haven't done before.

  6. #6
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    New Zealand
    Posts
    295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Field (Word 97)

    John a possibly simpler solution, are you able to map a drive directly to the current project folder??? then it would always look like xroject. The mapping could be shifted if a new folder was required????

  7. #7
    Star Lounger
    Join Date
    Jun 2001
    Location
    Brisbane Australia
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Field (Word 97)

    Hi Mike

    Unfortunately that is not an option. This is a large corporate network and they don't like us playing around with things like that. It really has to be something non-intrusive which can exist in the document itself - this is all because the long file names and path names are starting to encroach into available space in the footers and I

  8. #8
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Filename Field (Word 97)

    John

    I think it would be simplest to insert the abbreviated file path into one of the document properties every time the file is saved. You could do this by hijacking the FileSave function.

    Alternatively you could use the AutoOpen or AutoClose event to fire a macro to do the work of modifying the document property.

    Whichever event you choose will have drawbacks but I don't think you need to go completely overboard and capture all events - just pick one that suits.

    I would then use a field within the document to display that particular file property. This way the user can decide to include the field or not. If the field is already present in the template then they won't need to think about it unless they want it removed. Make sure you update the fields in the document after you update the file property.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  9. #9
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Filename Field (Word 97)

    John,

    Sorry I couldn't get back to you sooner on how to do the actual insert. I saw the other replies so view this as another option.

    Here's a little macro that builds on what I sent you last time. Make whatever changes to the first part that you had thought appropriate.

    <pre>Sub abbrevpath()
    Dim EntireName As String, ShortName As String
    EntireName = ActiveDocument.fullname
    ShortName = "G:..." & Mid(EntireName, 18) 'or whatever you want
    ' Update footer - this is the new stuff.
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Selection.HomeKey Unit:=wdStory
    Selection.InsertBefore (ShortName)
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End Sub
    </pre>


    What the new stuff does:
    - finds the footer associated with the current page. I thought you said you only had 1 section and 1 footer. So it doesn't matter what page you're on, this statement will find THE footer and what you insert will apply to all of them. But if you had lots of footers that this had to be done for, you'd need a loop that went thru all the footers in the document (story) in place of this statement and executed the next 2 statements inside the loop
    - goes to the beginning of the footer (probably not necessary since you'd be at the beginning of the footer based on the previous statement, I think - told you I wasn't great at this stuff)
    - inserts the ShortName before anything.
    - returns to the main document. You might want to return to a particular place - like where you were before calling the macro. I'm not sure if this will do that. But the macro could be expanded to insert a bookmark at the current location before seeking the footer, doing the rest of the footer stuff, returning to the location of the main document where the bookmark was, and then deleting the bookmark.

    You do have to save a new document before running the macro (I know you knew that). To run the macro, you can go to Tools | Macros or customize your toolbar to have a button that runs the macro. If you don't know how to do this, post back.

    Fred

  10. #10
    Star Lounger
    Join Date
    Jun 2001
    Location
    Brisbane Australia
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Field (Word 97)

    Hey thanks Fred [and Andrew and Mike also].

    I'm home for the Easter break but I'll try this out when I'm back in the office on Tuesday. I'll let you know how it turns out.

  11. #11
    Star Lounger
    Join Date
    Jun 2001
    Location
    Brisbane Australia
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Field (Word 97)

    Andrew

    Your suggestion makes a lot of sense to me now I have experimented with Fred's code. What I am finding there is that it inserts the text string every time the macro is run - this doesn't make the solution very dynamic as it is entirely possible that the files will move or be renamed and the footer needs to be able to recognise this fact.

    How can I access a "property" to insert the data? I've tried the VBA help but I must be looking in the wrong place.

    I would like to be able to place the data into a field that I can reference in the footer. When the filename [or path] changes I must be able to update this data. The footer must recognise the data as being changed but not recursively insert text.

  12. #12
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Filename Field (Word 97)

    John,

    In fact, I was thinking of the Custom Document Property approach when you first posed this. It didn't seem warranted based on what you had mentioned at the time. However, if the file gets moved around a lot that might be the easiest. A similar approach would be to use a bookmark whose value is the current path name. In either case, those would be inserted in the footer.

    In either case, you'd want, as Andrew suggested, to use one of the events associated with the file to actually do the triggering of the code and inserting of the current path. Right now, I can't get to it but let's see if someone else can help out. I might be able to get to it by the end of the week. In the mean time, here's some tidbits I've gotten from the lounge:

    To cycle thru the custom properties:
    <pre>For Each p In ActiveDocument.CustomDocumentProperties
    If p.Name = "shortpath" Then 'do whatever, like set a new value
    p.Value = "G:..." & shortname 'or whatever
    next p
    </pre>


    you can also create a custom property in VBA but I don't think you need to do that. Your code could test to see if you find "shortpath" in the loop and create it if not found. I would just create it manually. But if you want to, here's some more code from the lounge (hopefully clear)

    <pre>Public Sub InsertCustomDocProp()
    'checks for custom prop named "TestCustomDocProp"
    If bCustomDocPropExists("TestCustomDocProp") = False Then
    ActiveDocument.CustomDocumentProperties.Add _
    Name:="TestCustomDocProp", LinkToContent:=False, Value:="TestPropValue", _
    Type:=msoPropertyTypeString
    End If
    End Sub

    Public Function bCustomDocPropExists(strCustomDocPropName As String) As Boolean
    Dim i As Long
    Dim objCustDocProps As DocumentProperties
    Set objCustDocProps = ActiveDocument.CustomDocumentProperties
    For i = 1 To objCustDocProps.Count
    If objCustDocProps(i).Name = strCustomDocPropName Then
    bCustomDocPropExists = True
    GoTo FunctionExit
    End If
    Next 'i
    bCustomDocPropExists = False 'not really necessary!
    FunctionExit:
    Set objCustDocProps = Nothing
    End Function
    </pre>


    Once you have the property, inserting it into the footer using the code I gave you and putting it into some event module should get you what's needed.

    Fred

  13. #13
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Filename Field (Word 97)

    John

    The VBA to insert the text value into the document property will look like this
    ActiveDocument.BuiltInDocumentProperties(wdPropert yCategory) = strPath
    where strPath is the string value you want to use

    In the document your footer should then contain the field { DocProperty Category }

    Whenever the document property is updated the fields in the document could also be updated with VBA or you could just rely on Word to update it when it sees fit. Fields in the headers and footers will update automatically whenever they have to be displayed so they update without the usual triggers anyway.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  14. #14
    Star Lounger
    Join Date
    Jun 2001
    Location
    Brisbane Australia
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Field (Word 97)

    I must be getting close now I'm sure.

    I've coded the following and it seems to function correctly:

    Sub MirrorPath()
    '
    ' MirrorPath Macro
    ' Macro created 03/04/2002 by John Heidemann
    '
    Dim EntireName As String, ShortName As String, TestName As String
    EntireName = ActiveDocument.FullName
    '
    ' Store the current full path
    '
    TestName = Left(EntireName, 33)
    '
    ' If the document exists in the designated location then update the path
    '
    If TestName = "G:Project OfficeProject Mirror" Then
    ShortName = "G:..." & Mid(EntireName, 33)
    Else
    ShortName = EntireName
    End If
    ActiveDocument.BuiltInDocumentProperties(wdPropert yCategory) = ShortName

    End Sub

    I've also added the DocProperty Category to the footer and it functions as I expect it to also. Where I am having a problem still though is in hijacking the Filesave and FileSaveAs events. I have tried the folllowing but it doesn't seem to work.

    Sub FileSaveAs()
    '
    ' Call Mirrorpath()
    '
    Call MirrorPath

    With Dialogs(wdDialogFileSaveAs)
    .Show
    End With

    End Sub

    I need an easier reference to find my way around VBA.

  15. #15
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Filename Field (Word 97)

    Yes, you were almost there. Two problems
    Drop the word Call
    Run the document setting after the name changes not before

    I rewrote the subs to be a sub and function. The primary benefit of this is that the the function is not visible as a macro that someone can run from the list.
    <pre>Sub FileSaveAs()
    Dialogs(wdDialogFileSaveAs).Show
    'Make sure the document has a name before this function is called
    'don't put this line before the naming in the first line
    MirrorPath ActiveDocument.FullName
    ActiveDocument.Fields.Update
    End Sub

    Function MirrorPath(sFullName As String)
    Dim sPathLeft As String, sCommonPath As String, sNewPath As String

    sCommonPath = "G:Project OfficeProject Mirror"
    ' Define the leftmost characters in the full file path
    sPathLeft = Left(sFullName, Len(sCommonPath))

    ' If the document exists in the common location then shorten the path
    If sPathLeft = sCommonPath Then
    sNewPath = "G:..." & Mid(sFullName, Len(sCommonPath))
    Else
    sNewPath = sFullName
    End If
    ActiveDocument.BuiltInDocumentProperties(wdPropert yCategory) = sNewPath
    End Function</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

Page 1 of 2 12 LastLast

Posting Permissions

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