Search code examples
excelvb.netadd-in

Open specific Folder in excel using vb.net in VisualStudio


I have to update an add-in that not written by me and i have to add a button that opens the specific path. I have no idea about this add-in. I could just add the button...

    Private Sub RBOpenFolder_OnClick(sender As Object, control As IRibbonControl, pressed As Boolean) Handles RBOpenFolder.OnClick

    End Sub

....\AppData\Local\AppName I have to access this address but the path changes on each pc has this add-in.

So in my computer C:\Users\Taylan\AppData\Local\AppName

Regards


Solution

  • If I am understanding this correctly, you are trying to access the user's local AppData folder via your application.

    To achieve this, simply use the Environment.GetFolderPath and specify the local application data folder:

    Dim FolderNameAs String
    
    FolderName = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
    

    In your case, this would return:

    C:\Users\Taylan\AppData\Local\
    

    You will then need to append the remainder of your path to this, so add AppName:

    FolderName = System.IO.Path.Combine(FolderName, "AppName")
    

    The FolderName variable will then contain:

    C:\Users\Taylan\AppData\Local\AppName