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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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
 
Upvote 0
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."
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,717
Members
449,050
Latest member
MiguekHeka

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