Find file path on users system.

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
Hi there,

I have an excel doc that opens a file within their system. E.g. Finance2011.xls but the macro needs to know the destination of the file. At the moment I have manually put the file path on each system individually. I'd there anyway I can write a code to insert the systems file path into the open code line
E.g
Workbook.open("File:///\\system34\mydocuments\Finance2011.xls")
So the code will find the ("File:///\\system34\mydocuments\" part
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Why are you using File:///?

Are you wanting to use UNC? Unless you have changed it, My Documents is usually on the users system.
 
Upvote 0
Hi thanks for reply I don't know why I use the File:/// bit. I just know it works with that.the users are apart of a networksybe it's due to that I think this apart never changes I just want the \\\mydocuments\ part. :)
 
Upvote 0
Code:
Private Declare Function SHGetSpecialFolderPath _
   Lib "shell32.dll" _
   Alias "SHGetSpecialFolderPathA" _
   (ByVal hWnd As Long, _
   ByVal lpszPath As String, _
   ByVal nFolder As Integer, _
   ByVal fCreate As Boolean) As Boolean

Private Const CSIDL_PERSONAL = &H5

Function GetMyDocuments()
Dim blnReturn As Long
Dim strBuffer As String
strBuffer = Space(255)
blnReturn = SHGetSpecialFolderPath(0, _
   strBuffer, _
   CSIDL_PERSONAL, _
   False)
   
strBuffer = Left(strBuffer, InStr(strBuffer, Chr(0)) - 1)
GetMyDocuments = strBuffer
End Function

Sub TEST()
MsgBox "My Documents Location is: " & GetMyDocuments
End Sub
 
Upvote 0
Thanks this works a treat.
Anyway of finding out where a certain file name is on ur system ??
Eg finance.xls I'd in 2011 folder
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top