Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Get path of open workbook

I prefer the cheat to win method. This example only works if the document you
are working on is the last file that was opened. This Sub is meant to save
the currently opened text file (CSV, TAB, etc.) into an Excel file by the
originating name of the file.

Public Sub Save_Workbook()
Dim sPath as String
'Get full file path and name from recent files list, #1 is the most
recently opened
sPath = Application.RecentFiles.Item(1).Name
'Find current directory (designated by "\" as right most character), path
is on left, file name is to the right.
For s = Len(sPath) To 1 Step -1
If Mid(sPath, s, 1) = "\" Then
sPath = Left(sPath, s)
Exit For
End If
Next s
'Save the workbook as last worksheet name
Activeworkbook.SaveAs sPath & Worksheets(Worksheets.Count).Name & ".xls",
xlWorkbookNormal
End Sub

That should do it.



"Selina" wrote:

How do I get the full path of the Excel workbook that is open and active ?
File System Object requires the full path before opening, creating and
manipulating files. What if the path is "unknown" ? I am trying to put the
path and workbook name and worksheetname into the footer of each sheet of the
active workbook. Thank you.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Get path of open workbook

Or:

Private Function MyName() As String
MyName = ThisWorkbook.Name
End Function

Private Function MyFullName() As String
'---------------------------------------------------------------------------------------
' Procedure : MyFullName
'return name and path of current workbook
MyFullName = ThisWorkbook.Fullname
End Function

Function fPath()
' Purpose : Compares two above to strips the workbook name and return the
filepath only
' returns the filepath for a file
fPath = Left(MyFullName, Len(MyFullName) - Len(MyName))
End Function





"Peridox" wrote in message
...
I prefer the cheat to win method. This example only works if the document
you
are working on is the last file that was opened. This Sub is meant to save
the currently opened text file (CSV, TAB, etc.) into an Excel file by the
originating name of the file.

Public Sub Save_Workbook()
Dim sPath as String
'Get full file path and name from recent files list, #1 is the most
recently opened
sPath = Application.RecentFiles.Item(1).Name
'Find current directory (designated by "\" as right most character),
path
is on left, file name is to the right.
For s = Len(sPath) To 1 Step -1
If Mid(sPath, s, 1) = "\" Then
sPath = Left(sPath, s)
Exit For
End If
Next s
'Save the workbook as last worksheet name
Activeworkbook.SaveAs sPath & Worksheets(Worksheets.Count).Name &
".xls",
xlWorkbookNormal
End Sub

That should do it.



"Selina" wrote:

How do I get the full path of the Excel workbook that is open and active
?
File System Object requires the full path before opening, creating and
manipulating files. What if the path is "unknown" ? I am trying to put
the
path and workbook name and worksheetname into the footer of each sheet of
the
active workbook. Thank you.



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
How to see full path name of open workbook? Joe User[_2_] Excel Discussion (Misc queries) 5 March 21st 10 08:29 PM
Macro to open Workbook in default path. Richard Excel Discussion (Misc queries) 2 October 7th 07 02:24 PM
How to get the full path name of the open workbook in a macro Flystar[_10_] Excel Programming 3 May 13th 04 09:16 AM
how to open workbook without hardcoding path Michael Turner Excel Programming 3 November 20th 03 12:12 PM
Checking if workbook open (where path is unknown) [email protected] Excel Programming 0 September 4th 03 11:13 PM


All times are GMT +1. The time now is 01:43 AM.

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

About Us

"It's about Microsoft Excel"