Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2008, 08:30 AM
Registered User
 
Join Date: Mar 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieve Active File Path

I need to retrieve the current path of the active file to avoid "hard coding" the path into my application. I know that win32api commands can be used for this but can not find any Excel VBA examples on the net.

Any help?

 
Old March 6th, 2008, 07:15 PM
Authorized User
 
Join Date: Nov 2007
Posts: 48
Thanks: 0
Thanked 4 Times in 4 Posts
Default

francois.timms,

Try:

Code:
Sub GetActiveWorkbookPath()
    Dim FullPathFileName
    Dim GetFilePath
    FullPathFileName = ActiveWorkbook.FullName
    GetFilePath = Mid(FullPathFileName, 1, InStrRev(FullPathFileName, "\"))
    MsgBox "Active Workbook Full Path = " & GetFilePath
End Sub

Have a great day,
Stan

stanleydgromjr

Windows Vista Business and Excel 2003, 2007.
 
Old March 10th, 2008, 01:43 AM
Registered User
 
Join Date: Mar 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Stan

Thanks a mil! Works like a charm!

 
Old March 24th, 2008, 05:14 PM
Authorized User
 
Join Date: Mar 2008
Posts: 35
Thanks: 0
Thanked 1 Time in 1 Post
Default

The way to find the path of the [u]active</u> Excel file is pretty straightforward:
strPath = Activeworkbook.Path

Now, Stan's way can be used to get the path of anyone of the open Workbooks.
Suppose "File1.xls" is one of the open workbooks.
Code:
Dim strFile as string, strPath as String
strFile = "File1.xls"
strPath = GetFilePath(strFile)

Function GetFilepath(ByVal strFile as String) as String
GetFilePath = Mid(Workbooks(strFile).FullName,1,InstrRev(Workbooks(strFile).FullName, "\") -1)
End Function





Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieve numbered node path from xml jeft0nes XSLT 6 July 20th, 2007 03:59 PM
How to retrieve the UserID from Active Directory t jdm_EG Infopath 3 May 29th, 2007 02:50 PM
how to ge tthe path of active document??? keepsmiling_sruti VB How-To 5 July 6th, 2005 01:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.