Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    May 2006
    Location
    Currently in Europe
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Can a Word macro test its run-time environment?

    Is there a way to make a Word macro test its run-time environment?

    In other words, is it possible for a macro to establish whether it is running from a local hard drive or from a network location?

    Any ideas welcome!
    Stylus

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    205
    Thanks
    4
    Thanked 49 Times in 40 Posts
    Yes, the macro can look at the value of WordBasic.FilenameInfo(ThisDocument.FullName, 6). The FilenameInfo function with the second argument set to 6 returns the UNC form of the path in the first argument. The ThisDocument object is the file that contains the running macro code, and its .FullName member contains the file's path.

    If the first two characters of the returned string are "\\" then the macro is running from a network location. If the first character is a letter and the second character is a colon, then the macro is running from either a local drive or a network drive that has been mapped to a drive letter. I think that in the latter case you'll have to use a Windows API call to distinguish which it is. See http://access.mvps.org/access/api/api0003.htm for some sample code.

  3. #3
    2 Star Lounger
    Join Date
    May 2006
    Location
    Currently in Europe
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thank you!

    What I want to do is make my global template only work from a network location.

    I set up a test for WordBasic.FilenameInfo(ThisDocument.FullName, 6) at beginning of the custom ribbon macro, so that it displays a message box with the result. It displays the network address, so I know the test is run and works. When I add Exit Sub to this test then I get results I don't understand.

    If I open Word, the global template is loaded and it's custom ribbon WORKS, even though I get the message box display which tells me that the test has run. If I then use the custom ribbon to open a custom template (i.e. a second document) the global is not loaded at all - yet no message box displays.

    It looks to me like the exit sub path only works when the global's custom ribbon is used to open another doc, not when the the global itself is loaded. Yet, when the global is loaded the message box displays... so... the test is run... Hmmmm.

    I hope I have explained this sufficiently.

    Any ideas?
    Stylus

  4. #4
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    I don't understand what is happening and don't have the facilities to test things, but I do have a suggestion, or three.

    If you truly want the global loaded only if it is on the network, you could use a second global to load it. The second global is the only one loaded when Word starts. If it is being run from the network, it loads your original global from the network, as a global Add-In. If it is not being run from the network, it exits the sub before loading the first one. The second global (the loader) has no ribbon modifications or other purposes.

    Not sure why you want this only run if it is being run from the network. My experience with global templates has been that if they are loaded from a network drive they are locked from editing so long as anyone on the network has Word open. This may just be showing my outdated information and limited experience with network permissions. In my experience, the loading of the global activates a locking file. (My last attempt at this was more than ten years ago.) My preference has been to have the global template copied to the user's own startup folder (local or network) through the login file.
    Charles Kyle Kenyon
    Madison, Wisconsin

Posting Permissions

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