#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Current Directory

I am writing a Macro that does some stuff then saves the file as "NAME.txt"
but the directory that I am will change with each new file. How do I grab
the directory of the active workbook? I can grab the full file path
(ActiveWorkbook.FullName) but I can not convert this to the directory. Any
help?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default Current Directory

=CELL("filename") will return the file's directory path.

Keep the quotes and filename. Odd function but it gives you the info you
need.

Dave
--
Brevity is the soul of wit.


"Mallasch" wrote:

I am writing a Macro that does some stuff then saves the file as "NAME.txt"
but the directory that I am will change with each new file. How do I grab
the directory of the active workbook? I can grab the full file path
(ActiveWorkbook.FullName) but I can not convert this to the directory. Any
help?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,290
Default Current Directory

Another way.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

Sub FindWhatFolder()
MsgBox WhatFolder(ThisWorkbook.Path)
End Sub

Function WhatFolder(strPath) As String
Dim FSO As Object
Dim oFold As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFold = FSO.GetFolder(strPath)
WhatFolder = oFold.Path
End Function
'--------------------


"Mallasch"

wrote in message
I am writing a Macro that does some stuff then saves the file as "NAME.txt"
but the directory that I am will change with each new file. How do I grab
the directory of the active workbook? I can grab the full file path
(ActiveWorkbook.FullName) but I can not convert this to the directory. Any
help?
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Current Directory

That will actually tell you the name of drive/path/filename/sheet name that was
active when excel last calculated.

In this case, you'd want to specify a range:

=cell("Filename",a1)

===========
In code, you could use:

msgbox activeworkbook.path



Dave F wrote:

=CELL("filename") will return the file's directory path.

Keep the quotes and filename. Odd function but it gives you the info you
need.

Dave
--
Brevity is the soul of wit.

"Mallasch" wrote:

I am writing a Macro that does some stuff then saves the file as "NAME.txt"
but the directory that I am will change with each new file. How do I grab
the directory of the active workbook? I can grab the full file path
(ActiveWorkbook.FullName) but I can not convert this to the directory. Any
help?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Current Directory

Thanks. activeworkbook.path worked well. I was using
activeworkbook.fullname which gave me the filename that I didn't want...

"Dave Peterson" wrote:

That will actually tell you the name of drive/path/filename/sheet name that was
active when excel last calculated.

In this case, you'd want to specify a range:

=cell("Filename",a1)

===========
In code, you could use:

msgbox activeworkbook.path



Dave F wrote:

=CELL("filename") will return the file's directory path.

Keep the quotes and filename. Odd function but it gives you the info you
need.

Dave
--
Brevity is the soul of wit.

"Mallasch" wrote:

I am writing a Macro that does some stuff then saves the file as "NAME.txt"
but the directory that I am will change with each new file. How do I grab
the directory of the active workbook? I can grab the full file path
(ActiveWorkbook.FullName) but I can not convert this to the directory. Any
help?


--

Dave Peterson

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
Excel 2k3 query path to current directory busypgmr Excel Discussion (Misc queries) 1 September 5th 06 10:05 PM
Saving to "open" directory 9119 New Users to Excel 2 January 19th 06 02:39 PM
Staying it its own directory. Steven Excel Worksheet Functions 1 January 7th 06 11:25 PM
Update Links to current Directory?? Pulcue Excel Discussion (Misc queries) 1 June 27th 05 12:11 PM
Extracting data from the current date Cali00 Excel Worksheet Functions 2 April 14th 05 05:49 AM


All times are GMT +1. The time now is 04:10 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"