Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default get the parent folder of the working folder

i wonder that get the parent folder of folder of current excel file
using macro.

ex) working directory : c:\aa\bb
answer : c:\aa



*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default get the parent folder of the working folder

"tom taol" wrote in message
...
: i wonder that get the parent folder of folder of current excel file
: using macro.
:
: ex) working directory : c:\aa\bb
: answer : c:\aa
:
Use the GetParentFolderName Method of the FileSystemObject. See MSDN link
below
http://tinyurl.com/afbgz
Paul D


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default get the parent folder of the working folder

Sub GetParent()
Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
MsgBox oFSO.GetFile(ActiveWorkbook.FullName).ParentFolder .ParentFolder.Path
End Sub


--
HTH

Bob Phillips

"tom taol" wrote in message
...
i wonder that get the parent folder of folder of current excel file
using macro.

ex) working directory : c:\aa\bb
answer : c:\aa



*** Sent via Developersdex http://www.developersdex.com ***



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default get the parent folder of the working folder

Tom,
How about:
Folders = Split(ThisWorkbook.Path, "\")
MsgBox Folders(UBound(Folders) - 1)

Need error checking in the situation of "C:\MyFile.xls".

NickHK

"tom taol" wrote in message
...
i wonder that get the parent folder of folder of current excel file
using macro.

ex) working directory : c:\aa\bb
answer : c:\aa



*** Sent via Developersdex http://www.developersdex.com ***



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default get the parent folder of the working folder



"NickHK" wrote in message
...

Need error checking in the situation of "C:\MyFile.xls".


Mine also fails for root files, so also needs error handling.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default get the parent folder of the working folder

Mine also fails for root files, so also needs error handling.

Here's a slight change that may help with root files.

Sub GetParent()
Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")

With oFSO.GetFile(ActiveWorkbook.FullName).ParentFolder
If .IsRootFolder Then
'No Parent Folder
Debug.Print .Path
Else
Debug.Print .ParentFolder.Path
End If
End With
End Sub

HTH :)
--
Dana DeLouis
Win XP & Office 2003


"Bob Phillips" wrote in message
...


"NickHK" wrote in message
...

Need error checking in the situation of "C:\MyFile.xls".


Mine also fails for root files, so also needs error handling.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default get the parent folder of the working folder

I could have (should have?) done that myself, but I guess I am too lazy.

Thanks Dana.

Bob

"Dana DeLouis" wrote in message
...
Mine also fails for root files, so also needs error handling.


Here's a slight change that may help with root files.

Sub GetParent()
Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")

With oFSO.GetFile(ActiveWorkbook.FullName).ParentFolder
If .IsRootFolder Then
'No Parent Folder
Debug.Print .Path
Else
Debug.Print .ParentFolder.Path
End If
End With
End Sub

HTH :)
--
Dana DeLouis
Win XP & Office 2003


"Bob Phillips" wrote in message
...


"NickHK" wrote in message
...

Need error checking in the situation of "C:\MyFile.xls".


Mine also fails for root files, so also needs error handling.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling pdf files from general folder to specific folder [email protected] Excel Discussion (Misc queries) 2 September 8th 09 09:41 PM
how can i change my default working folder to a networked folder? wizard1154 Excel Discussion (Misc queries) 4 April 18th 07 07:29 PM
How to decide folder-depth or How to select more folders/subfolders (folder-tree) ? Subteam Excel Discussion (Misc queries) 2 May 7th 06 08:14 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
Parent Folder Bruce Excel Programming 2 September 6th 05 03:40 AM


All times are GMT +1. The time now is 11:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"