none
Excel Ribbon - Application.StartupPath RRS feed

  • Question

  • Im trying to get the startup path for the excel workbook location.

    In VBA or interop services,   application.startuppath   seems to work fine.

    but when working from a ribbon addin project,  Globals.ThisAddin.Application.StartupPath  returns the path of the addin, not the application's workbook.

    I need to resolve the file path to the worksheet opened, that is being managed by the addin, not the addin itself.

    Is there a way to achieve this in a ribbon ?

    ............

    Public Class ThisAddIn
        
        Private Sub Application_WorkbookOpen(Wb As Microsoft.Office.Interop.Excel.Workbook) Handles Application.WorkbookOpen

            MsgBox(Wb.Application.StartupPath)

        End Sub

    End Class

    ............

    Thanks

    • Moved by Youen Zen Thursday, July 26, 2012 5:12 AM To provide better support (From:Visual Basic General)
    Wednesday, July 25, 2012 6:24 PM

Answers

  • Hi NDNull,

    Thank you for posting in the MSDN Forum.

    According to your description, I suggest you use Workbook.FullName property to get the Workbook's location.

    My code is as follows:

    private void button1_Click(object sender, RibbonControlEventArgs e)
    {
        MessageBox.Show(String.Format("{0}\n{1}", 
            Globals.ThisAddIn.Application.ActiveWorkbook.FullName,
            Globals.ThisAddIn.Application.ActiveWorkbook.FullName.Replace(
            Globals.ThisAddIn.Application.ActiveWorkbook.Name, "")));
    }
    

    Effect of the code above: 

    Hope it helps.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, July 26, 2012 6:03 AM
    Moderator

All replies

  • You might want to post to the Visual Studio Tools for Office forum if you don't get an answer here.

    http://social.msdn.microsoft.com/Forums/en-US/vsto/threads


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, July 25, 2012 7:50 PM
  • Hi NDNull,

    Thank you for posting in the MSDN Forum.

    According to your description, I suggest you use Workbook.FullName property to get the Workbook's location.

    My code is as follows:

    private void button1_Click(object sender, RibbonControlEventArgs e)
    {
        MessageBox.Show(String.Format("{0}\n{1}", 
            Globals.ThisAddIn.Application.ActiveWorkbook.FullName,
            Globals.ThisAddIn.Application.ActiveWorkbook.FullName.Replace(
            Globals.ThisAddIn.Application.ActiveWorkbook.Name, "")));
    }
    

    Effect of the code above: 

    Hope it helps.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, July 26, 2012 6:03 AM
    Moderator