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
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
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
I suppose the simplest way to do it would be changing the current directory then assigning that to a variable[VBA]ChDir ActiveDocument.Path
ChDir ".."
myPath = CurDir[/VBA]
K :-)
Hi Killian,
I knew there were dots in the solution somewhere, and having now RTFH I tried:
[VBA]
Sub NextLevel()
Debug.Print ActiveDocument.Path
ChDir ActiveDocument.Path
ChDir ".."
mypath = CurDir
Debug.Print mypath
End Sub
[/VBA]
and got
[VBA]M:\1174 PKC_Partnering_Kitchens\MergeLetters
Z:\
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
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:[vba]Sub NextLevel()
Dim mypath As String
mypath = ActiveDocument.Path
Debug.Print mypath
ChDir mypath
ChDrive mypath
ChDir ".."
mypath = CurDir
Debug.Print mypath
End Sub[/vba]Matt
Is there a particular reason for not wanting to do string manipulation? (other than curiosity)
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Theres also always[vba] Dim fso As Object
Set fso = CreateObject("scripting.filesystemobject")
MsgBox fso.GetParentFolderName(ActiveDocument.Path)
Set fso = Nothing[/vba]Just as another alternative
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
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Is 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 folderOriginally Posted by mdmackillop
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
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
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.
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
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'