none
Inserting object using VBA RRS feed

  • Question

  • Hello,

    Would for some tasks like to insert a link to an object (.pdf file) from the note dialog box. This work just fine doing it manually. Is it possible to do it using VBA? Have tried to record a macro, but one line is is recorded where a text note can be inserted.

    This would be a great feature as we then can get direct access to a file which includes all remainig items on the Projects directly from within Project.

    Grateful for any input.

    Kind regards //Anders

    Monday, April 25, 2016 6:14 AM

Answers

  • Anders,

    I'm not confident it is possible with VBA. Normally if you can't record an operation in a macro, that means there is no object library equivalent to that operation. In particular, manual formatting of the Notes field is much more extensive than what you can do to the Notes field using VBA. For example, even though you can apply various font formats and bullets to the Notes field, that formatting cannot be accomplished with VBA. However, what you can do is to use the InsertObject Method in your macro. That will bring up the Insert Object window for the user to select the desired file.

    But maybe a better approach is to not put the file reference in the Notes field, rather, use the Hyperlink field to reference the file. For that you would use the InsertHyperLink Method. This is the example from the Project Help file:

    Sub Insert_Hyperlink()
        'Activate Gantt Chart view
        ViewApply Name:="&Gantt Chart"
        SelectRow Row:=2, RowRelative:=False
        InsertHyperlink Name:="http://MSDN", Address:="http://msdn.microsoft.com/", SubAddress:="", ScreenTip:=""
    End Sub

    Hope this helps.

    John

    • Marked as answer by AT_lamnea Tuesday, April 26, 2016 6:00 AM
    Monday, April 25, 2016 2:55 PM

All replies

  • Anders,

    I'm not confident it is possible with VBA. Normally if you can't record an operation in a macro, that means there is no object library equivalent to that operation. In particular, manual formatting of the Notes field is much more extensive than what you can do to the Notes field using VBA. For example, even though you can apply various font formats and bullets to the Notes field, that formatting cannot be accomplished with VBA. However, what you can do is to use the InsertObject Method in your macro. That will bring up the Insert Object window for the user to select the desired file.

    But maybe a better approach is to not put the file reference in the Notes field, rather, use the Hyperlink field to reference the file. For that you would use the InsertHyperLink Method. This is the example from the Project Help file:

    Sub Insert_Hyperlink()
        'Activate Gantt Chart view
        ViewApply Name:="&Gantt Chart"
        SelectRow Row:=2, RowRelative:=False
        InsertHyperlink Name:="http://MSDN", Address:="http://msdn.microsoft.com/", SubAddress:="", ScreenTip:=""
    End Sub

    Hope this helps.

    John

    • Marked as answer by AT_lamnea Tuesday, April 26, 2016 6:00 AM
    Monday, April 25, 2016 2:55 PM
  • John,

    Thanks a lot for your quick and informative reply.

    In one way that is even better than the proposed usage of insert object. The only reason for why notes was preferred was that the notes dialog box can be reached from within the Team Planner as well. However still there are the same number of mouse button clicks to reach the file with the hyperlink (which not is avialable from the Team Planner view ) as it would have been from the notes dialog box.

    What you just assisted with was to give our planning department direct access, by one or max three mouse button clicks to the complete list of Components and parts remaning to be delivered from subcontractors prior to our assembly work can begin. This is a great feature and will be very much appreciated.

    Thank you very much John for all your help, you are just great!

    Kind regards //Anders

    Tuesday, April 26, 2016 6:00 AM
  • Anders,

    You're very welcome and thanks for the informative feedback.

    John

    Tuesday, April 26, 2016 2:39 PM