File Path

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
Is there a way to have a macro pop-up a box with the file path of the excel workbook. I'm know that this is easy but there's a catch!

PROBLEM: I need the file path for the workbook to be copyable. The user needs to copy and paste the file path into a separate program.

THOUGHT: I was thinking some sort of message box that is triggered by a macro that has an Input field pre-populated with the full file path, that can be copied, and instructions for what the user needs to do.

QUESTION: Is this doable?
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Misca

Well-known Member
Joined
Aug 12, 2009
Messages
1,589
You could create a UserForm with a TextBox. This piece of code types the path of the workbook to the Textbox1:
Code:
Private Sub UserForm_Initialize()
TextBox1.Text = ThisWorkbook.Path
End Sub
 

Misca

Well-known Member
Joined
Aug 12, 2009
Messages
1,589
I also found an easier way to do the same.

This one copies the path directly to the clipboard:
Code:
Dim DataObj As New MSForms.DataObject
    Dim S As String
    S = ThisWorkbook.Path
    DataObj.SetText S
    DataObj.PutInClipboard
    
MsgBox "This workbook's path " & vbNewLine & vbNewLine & S & vbNewLine & vbNewLine & "was copied to the clipboard."
 

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
Sorry I'm a little new to this. How would I apply the above code to a button as a macro?
 

Misca

Well-known Member
Joined
Aug 12, 2009
Messages
1,589
1) Press Alt + F11 to open the VBA Editor.
2) In the editor choose Insert --> Module. Now you're ready to type the code.
3) Type "Sub MyMacro" (without the quotes) and press Enter. The editor fills the "End Sub" for you. Now between those two lines paste the code from above.
4) Add the button to your worksheet (or whatever you prefer). Right click the object and select "Assign Macro". Select "MyMacro" from the list and press OK.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,402
Messages
5,511,147
Members
408,828
Latest member
Csmnvld

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top