home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows / 1993_Aces_Research_Dr._Windows_UPC_765872322017_shareware.iso / word / default.dir < prev    next >
Internet Message Format  |  1991-02-10  |  4KB

  1. From comp.windows.ms Thu Jan 10 12:18:20 1991
  2. From: fredf@microsoft.UUCP (Fred FREELAND)
  3. Date: 10 Jan 91 05:08:01 GMT
  4. Newsgroups: comp.windows.ms
  5. Subject: Default Directory for Word for Windows solution
  6.  
  7.  
  8. I've seen a lot of discussion in recent weeks about how to get Microsoft
  9. Word for Windows to remember the last directory you were in from session
  10. to session.  While there are a number of somewhat kludgy ways to do this,
  11. I offer the following programatic solution. It's what I use every day and
  12. it works without fail.  Hopefully someone else out there in netland can
  13. make some good use of it.
  14.  
  15. There are three routines that probably do not already exist in your version
  16. of Word for Windows, but they are recognized.  All you have to do is add
  17. the code shown below to macros with the names shown just above Sub MAIN for
  18. each case..
  19.  
  20. The key to this whole scheme is the API call into Windows used by the
  21. AutoExit macro.  This is what writes the WIN.INI entry that can be retrieved
  22. when Word for Windows is next started.
  23.  
  24. Enjoy!
  25.  
  26. -------------------------Code Begins Here-----------------------------------
  27. AutoeExec
  28. Sub MAIN
  29.   ' This procedure checks attempts to return to the last directory used by
  30.   ' Microsoft Word for Windows. It checks the WIN.INI file for a
  31.   ' DefaultDirectory entry and changes to the directory path found there.
  32.   ' No action is taken if no entry exists
  33.  
  34.   AName$ = "Microsoft Word"                   ' Set Application Name.
  35.   KName$ = "DefaultDirectory"                 ' Set Key name.
  36.   NewDir$ = GetProfileString$(AName$, KName$) ' Get the last directory used.
  37.   ChDir NewDir$                               ' Change directory.
  38. End Sub
  39.  
  40. AutoOpen
  41. Sub MAIN
  42.   ' This procedure determines the path of the file that was just opened.
  43.   ' It then causes Word for Windows to make that directory the current
  44.   ' default directory for future FileOpen operations.
  45.  
  46.   Path$ = ""                              ' Initialize Path$.
  47.   LastFile$ = FileName$(1)                ' Get path of last file opened.
  48.   I = Len(LastFile$)                      ' Get length of filespec.
  49.   While Path$ = ""
  50.     If Mid$(LastFile$, I, 1) = "\" Then   ' Starting from the right,
  51.       Path$ = Left$(LastFile$, I - 1)     ' look for the last directory
  52.     End If                                ' delimiter (\). Take everything
  53.                                           ' to the left of the delimiter
  54.                                           ' for the path.
  55.     I = I - 1
  56.   Wend
  57.   ChDir Path$                             ' Change directory
  58. End Sub
  59.  
  60. AutoExit
  61. 'WIN API procedure to write a WIN.INI entry.
  62. Declare Function WriteProfileString Lib "Kernel"(AName$, KName$, Repl$) As Integer
  63.  
  64. Sub MAIN
  65.   ' This procedure determines the directory path of the last file opened.
  66.   ' It then writes the path to the DefaultDirectory entry in the WIN.INI.
  67.  
  68.   AName$ = "Microsoft Word"                ' Set Application Name.
  69.   KName$ = "DefaultDirectory"              ' Set Key Name.
  70.   Repl$ = ""                               ' Initialize replacement string.
  71.   LastFile$ = FileName$(1)                 ' Get path of last file opened.
  72.   I = Len(LastFile$)                       ' Get length of filespec.
  73.   While Repl$ = ""
  74.     If Mid$(LastFile$, I, 1) = "\" Then    ' Starting from the right,
  75.       Repl$ = Left$(LastFile$, I - 1)      ' look for the last directory
  76.     End If                                 ' delimiter (\). Take everything
  77.                                            ' to the left of the delimiter
  78.                                            ' for the path.
  79.     I = I - 1
  80.   Wend
  81.   X = WriteProfileString(AName$, KName$, Repl$)   ' Write to WIN.INI file.
  82. End Sub
  83. ---------------------------Code Ends Here-----------------------------------
  84.  
  85. -- 
  86. Frederick F. Freeland Jr.                        "Of all the things I've lost,  Microsoft Corporation                               I miss my mind the most!"   One Microsoft Way  
  87. Redmond, WA 98052 (206) 882-8080                                                                                                                                internet: fredf@microsoft.beaver.washington.EDU                                 arpanet:  fredf%microsoft@uw-beaver.ARPA
  88. uucp:     uunet!microsoft!fredf                                                                                                                                 Opinions expressed over this signature are my OWN and not those of my employer! 
  89.  
  90.