0

I am trying to write a VBA to open up a file path to a direct folder. What is wrong with how I am doing it? Is this the right way to do it?

I have searched and used examples from here, but get an error (see below)

Sub OpenFolder()
    Dim FolderPath As String

    FolderPath = "C:\Users\myname\Desktop\AdaptiveThreatProtection\"

    Call Shell("explorer.exe """ & FolderPath & "", vbNormalFocus)

End Sub

lt123
  • 117
  • 1
  • 2
  • 8
  • 1
    Does this answer your question? [How to open a folder in Windows Explorer from VBA?](https://stackoverflow.com/questions/11205719/how-to-open-a-folder-in-windows-explorer-from-vba) – Geert Bellekens May 28 '20 at 13:59
  • That is what I was trying, but had no luck with it. I get the error: "Run-time error '5': Invalid procedure call or argument" – lt123 May 28 '20 at 14:05
  • It is unclear what to do with that folder. I don't know the specific intention, such as whether to open all Excel files in the folder and work. There are many examples of doing various tasks for a given folder. – Dy.Lee May 28 '20 at 14:20
  • I just want to open a specific file path. I have another program that saves a txt data file to that same path, So I want to be able to open that path in excel so I can then import that txt file and format it with various macros etc. – lt123 May 28 '20 at 14:23

1 Answers1

0
Sub OpenFolder()

    Dim MyFolder As String
    MyFolder = "C:\Users\myname\Desktop\AdaptiveThreatProtection"
    ThisWorkbook.FollowHyperlink MyFolder

End Sub

Using ThisWorkbook ended up working for me. It opens the exact file path.

lt123
  • 117
  • 1
  • 2
  • 8