Freelancer: rashedkhanrubel
Share:
Report Entry

Copy File Path of this workbook

Need to add reference to "Microsoft Forms 2 Object Library" to run the code

Contest Entry #2 for                                                 Excel VBA Copy File Path to Clipboard

Public Clarification Board

  • briandoherty22
    Contest Holder
    • 4 years ago

    Please let me know if that makes sense and if you would be able to update and corect it.

    • 4 years ago
    1. rashedkhanrubel
      rashedkhanrubel
      • 4 years ago

      Or should I give the modified code?

      • 4 years ago
    2. rashedkhanrubel
      rashedkhanrubel
      • 4 years ago

      Sub Copy_Workbook_Path()
      'add reference to "Microsoft Forms 2 Object Library"
      Dim wb As Workbook
      Dim Pt As String

      Set wb = ActiveWorkbook

      Pt = wb.Path & "\"

      With New MSForms.DataObject
      .SetText Pt
      .PutInClipboard
      End With

      End Sub

      • 4 years ago
  • briandoherty22
    Contest Holder
    • 4 years ago

    Thanks man this looks good, but it is not working properly when we try to run the code in a different workbook. For example, if the code is saved in Wkbk_1 and we run the code with Wkbk_2 as the ActiveWorkbook, we are getting the file path of Wkbk_1. It should pull whatever the ActiveWorkbook is and not where the code is saved.

    • 4 years ago