PDA

View Full Version : Solved: Next level folder



mdmackillop
10-19-2005, 09:03 AM
Hi All.
Activedocument.path returns the path to my document which is in a sub, sub folder. I want to get the sub folder, which is one level above. Can this be done without a string manipulation?
Regards
MD

Killian
10-19-2005, 09:44 AM
I suppose the simplest way to do it would be changing the current directory then assigning that to a variableChDir ActiveDocument.Path
ChDir ".."
myPath = CurDir

mdmackillop
10-19-2005, 09:59 AM
Hi Killian,
I knew there were dots in the solution somewhere, and having now RTFH I tried:

Sub NextLevel()
Debug.Print ActiveDocument.Path
ChDir ActiveDocument.Path
ChDir ".."
mypath = CurDir
Debug.Print mypath
End Sub


and got
M:\1174 PKC_Partnering_Kitchens\MergeLetters
Z:\

:banghead:

mvidas
10-19-2005, 10:17 AM
Hi Malcolm,

In your example, you're setting the current directory on the M drive.. IF the M drive is the current one. You have to add a ChDrive in there as well:Sub NextLevel()
Dim mypath As String
mypath = ActiveDocument.Path
Debug.Print mypath
ChDir mypath
ChDrive mypath
ChDir ".."
mypath = CurDir
Debug.Print mypath
End SubMatt

TonyJollans
10-19-2005, 02:41 PM
Is there a particular reason for not wanting to do string manipulation? (other than curiosity)

mvidas
10-19-2005, 02:45 PM
Theres also always Dim fso As Object
Set fso = CreateObject("scripting.filesystemobject")
MsgBox fso.GetParentFolderName(ActiveDocument.Path)
Set fso = NothingJust as another alternative :)

mdmackillop
10-19-2005, 02:45 PM
I knew there was a .. method of dealing with levels and thought it would be simpler! Not so it seems. I still don't understand where the Z: drive comes from though. It's on my system for my User area of the server, but I rarely if ever use it.
Regards
Malcolm

mvidas
10-19-2005, 02:49 PM
I knew there was a .. method of dealing with levels and thought it would be simpler! Not so it seems. I still don't understand where the Z: drive comes from though. It's on my system for my User area of the server, but I rarely if ever use it.
Regards
MalcolmIs it your MyDocuments folder, or does word use it as the default file path? My V drive does the same thing, as it is setup as the system's My Documents folder

mdmackillop
10-19-2005, 02:54 PM
Hi Matt,
Word is set to look for and save documents within the M drive. It's where all our "Contract" files are saved on the server

fumei
10-19-2005, 09:34 PM
I'd like to hear the answer to Tony's question. What is wrong with string manipulation? It is straightforward, and does not require the use of a reference to FileSystemObject. Not that is a real problem, but....I am curious as well.

mdmackillop
10-20-2005, 12:16 AM
Hi Gerry,
There is nothing "wrong" with string maniplulation, but I know how to do that. I was simply looking for other simply employed methods of which I was not aware.
Regards
Malcolm