1
Workbooks.Open Filename:="C:\Desktop\VBA\Phase 1\A.xlsx"

How do I open the file from desktop or documents of any user.

0m3r
  • 12,286
  • 15
  • 35
  • 71
yashika vaish
  • 201
  • 5
  • 19

1 Answers1

3

Multiple ways you can do that, pick the one that works for you-

Option Explicit
Public Sub Example()
    Dim FilePath As String
    FilePath = CreateObject("WScript.Shell") _
                  .specialfolders("Desktop") & "\VBA\Phase 1\A.xlsx"
    Debug.Print FilePath
End Sub

Option Explicit
Public Sub Example2()
    Dim FilePath As String
    FilePath = Environ("USERPROFILE") & "\Desktop\VBA\Phase 1\A.xlsx"
    Debug.Print FilePath
End Sub
0m3r
  • 12,286
  • 15
  • 35
  • 71