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?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Misca

Well-known Member
Joined
Aug 12, 2009
Messages
1,697
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,697
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,697
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,377
Messages
5,658,460
Members
418,446
Latest member
JValencia

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
Top