none
textbox using builtindocumentproperties RRS feed

  • Question

  • I'm trying to create an addin to incorporate the builtindocumentproperties. I have successfully created the macro in Project VBA.  However when I am trying the same in VSTO, I am getting the error. I have tried all possible options, but I have failed.

    I am inserting the VBA code for the form & the error which I am getting in VSTO.

    Option Explicit

    Public Sub cmd_OK_Click() If Me.txt_Project_Title.Value = "" Then MsgBox "Please enter a Project Title.", vbExclamation, "Project Data" Me.txt_Project_Title.SetFocus Exit Sub End If If Me.txt_Author.Value = "" Then MsgBox "Please enter an Author.", vbExclamation, "Project Data" Me.txt_Author.SetFocus Exit Sub End If If Me.txt_Company_Name.Value = "" Then MsgBox "Please enter the Company's Name.", vbExclamation, "Project Data" Me.txt_Company_Name.SetFocus Exit Sub End If If Me.txt_Start_Date.Value = "" Then MsgBox "Please enter a Project Start Date.", vbExclamation, "Project Data" Me.txt_Start_Date.SetFocus Exit Sub End If ActiveProject.BuiltinDocumentProperties("Title") = Me.txt_Project_Title.Value ActiveProject.BuiltinDocumentProperties("Author") = Me.txt_Author.Value ActiveProject.BuiltinDocumentProperties("Company") = Me.txt_Company_Name.Value ActiveProject.ProjectStart = Me.txt_Start_Date.Value Unload Me End Sub Private Sub UserForm_Initialize() Me.txt_Project_Title.Value = ActiveProject.BuiltinDocumentProperties("Title") Me.txt_Author.Value = ActiveProject.BuiltinDocumentProperties("Author") Me.txt_Company_Name.Value = ActiveProject.BuiltinDocumentProperties("Company") Me.txt_Start_Date.Value = DateFormat(ActiveProject.ProjectStart, pjDate_ddd_mmm_dd_yyy) End Sub

     

    The error I am getting in VSTO

     

     

    InvalidCastException was unhandled by user code

     

    An exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll but was not handled in user code

     

    Additional information: Conversion from type 'DocumentProperty' to type 'String' is not valid.

    Wednesday, January 22, 2014 1:21 PM

Answers

  • Hi Rick,

    Try this:

    Me.txt_Project_Title.Text = ActiveProject.BuiltinDocumentProperties("Title").Value

    • Marked as answer by Cindy Meister MVPModerator Saturday, January 25, 2014 4:24 PM
    • Unmarked as answer by RCKENI Friday, January 31, 2014 12:57 PM
    • Marked as answer by RCKENI Friday, January 31, 2014 12:58 PM
    Friday, January 24, 2014 1:04 PM

All replies

  • Hi Rick

    It always helps if you indicate which line (or lines) of code are triggering the error. I'm guessing:

    Me.txt_Project_Title.Value = ActiveProject.BuiltinDocumentProperties("Title")

    VB.NET is a bit different from VBA in a number of ways. One of them is that you can't benefit from "default properties" for an object. Try adding the .Value property at the end of the line (and all the others of this nature):

    Me.txt_Project_Title.Value = ActiveProject.BuiltinDocumentProperties("Title").Value


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, January 23, 2014 7:22 PM
    Moderator
  • When I try the

    Me.txt_Project_Title.Value = ActiveProject.BuiltinDocumentProperties("Title").Value

    I get the following error

    Error    1    'value' is not a member of 'System.Windows.Forms.TextBox'.  

    Friday, January 24, 2014 12:40 PM
  • Hi Rick,

    Try this:

    Me.txt_Project_Title.Text = ActiveProject.BuiltinDocumentProperties("Title").Value

    • Marked as answer by Cindy Meister MVPModerator Saturday, January 25, 2014 4:24 PM
    • Unmarked as answer by RCKENI Friday, January 31, 2014 12:57 PM
    • Marked as answer by RCKENI Friday, January 31, 2014 12:58 PM
    Friday, January 24, 2014 1:04 PM
  • Thank you so much. it is working
    Saturday, January 25, 2014 5:06 AM
  • It is working but when I close a project file keeping the MSProject open & when I open a new project file, & on accessing the form I get the data of the closed file instead of the open file. If I close the MSProject & then open a new file then it works fine.

    However when I am using project vba even if there are 2 or more files open & when I access the data from the form the data pertaining to the project file opens correctly.

    I think refreshing needs to be done in the VSTO code.

    Can you help me

    Monday, January 27, 2014 7:21 AM
  • It is working but when I close a project file keeping the MSProject open & when I open a new project file, & on accessing the form I get the data of the closed file instead of the open file. If I close the MSProject & then open a new file then it works fine.

    However when I am using project vba even if there are 2 or more files open & when I access the data from the form the data pertaining to the project file opens correctly.

    I think refreshing needs to be done in the VSTO code.

    Can you help me


    Friday, January 31, 2014 7:02 AM
  • Hello Rick,

    First of all, I'd recommend asking new questions in separate forum threads. Thus, forum readers can recognize the answer easily.

    Did you try to debug the code? It looks like you need to clear the old values on the form when you close the file.

    Friday, January 31, 2014 3:17 PM
  • How do i clear the old values in the form as suggexted by you.
    Wednesday, February 5, 2014 7:41 AM