none
Similar to EntryID property RRS feed

  • Question

  • Hello! 

    In Outlook Object Library some items have EntryID property.

    Like this:

    Dim objMail As Outlook.MailItem
    Set objMail = Application.CreateItem(olMailItem)
    SomeString = objMail.EntryID
    So, how can I get similar property for MS Project tasks?
    • Edited by GfiFer Friday, October 21, 2016 11:55 AM
    Friday, October 21, 2016 11:40 AM

All replies

  • Projects, activities, resources and assignments all have a UniqueID field which remains unchanged. (ID fields can change if a new activity is inserted, for example.) so:

    Dim t as Task, UID as Long

    Set t = ActiveCell.task

    UID = t.UniqueID

    Set t = ActiveProject.Tasks.UniqueID(UID)

    Friday, October 21, 2016 12:56 PM
  • It is not that role of this property that i need. 

    I want to use this property to make hyperlink in MS Word to different tasks in MS Project. If you insert to Word reference [outlook: objMail.EntryID] (something like [outlook: 2KJ42N4TN4NR4DNS]) and click it, then outlook will open this message. And I need something like this.

    Friday, October 21, 2016 2:09 PM
  • GfiFer,

    So where exactly is this "report" you mentioned in your Answers forum response? Is it a MS Word document or it is something in Outlook, or what?

    It isn't real clear exactly what you are trying to do. If I had to guess, it sounds like you want to be able to click on a hyperlink in some application (e.g. Word, Outlook, etc.) and have that link jump to a Project task. Is that correct? If not, please expand on what you want to do.

    John

    Friday, October 21, 2016 3:52 PM
  • click on a hyperlink in some application (e.g. Word, Outlook, etc.) and have that link jump to a Project task.

    Yes, it's absolutely correct. Is it possible with MS Project?
    Friday, October 21, 2016 9:32 PM
  • GfiFer,

    I've never worked with hyperlinks so I had to do a little research but yes you should be able to hyperlink from another application to a specific task in Project, assuming Project is installed on your PC (i.e. your boss actually has Project).

    So how do you do it? Project has 4 fields associated with hyperlinks. The two fields of interest are the Hyperlink Address and the Hyperlink SubAddress fields. For example, let's say you want to link to a Project file called Planning.mpp, task ID 13 which is located on your C: drive. The hyperlink syntax would be:

    wdDoc.Hyperlinks.Add Anchor:=Selection, Address:= _
            "C:\Users\John\Documents\Planning.mpp", SubAddress:= _
            "gantt chart!13", TextToDisplay:= _
            "C:\Users\John\Documents\Planning.mpp#gantt chart!13"

    Hope this helps.

    John

    Saturday, October 22, 2016 4:45 PM
  • But how can i put it to clipboard from macro?
    • Edited by GfiFer Tuesday, October 25, 2016 1:47 PM
    Tuesday, October 25, 2016 6:13 AM
  • GfiFer,

    Okay, let's back up a bit. You indicated you wanted VBA code to create a hyperlink in a Word document that sends the user to a particular task in a Project file. I gave you that. So what exactly do you want on the clipboard? Then once it's on the clipboard, then what?

    John

    Tuesday, October 25, 2016 4:37 PM
  • Oh, thank you very much for your help! The code you suggested actually work!

    So, when I have hyperlink I want to put it to the clipboard, to be able to use it in other applications. In the Word for example.

    Wednesday, October 26, 2016 5:18 AM
  • GfiFer,

    Sorry for the delay in responding. I'm still not clear on exactly what you are expecting to do and your abbreviated replies have not expanded on the total picture so let me take a couple guesses.

    You have a Word document. In that document you include hyperlinks to a Project file. When a user clicks on the link you want the user to be able to select the Project task that is selected by the link and then copy that task to the clipboard. That's easy, just have the user manually select the task row that was selected by the link and do a copy.

    However, you wanted to create the hyperlink using VBA and I gave you the syntax for that. If you are expecting the macro to then also copy that task to the clipboard, that can be done with additional VBA by creating a Project object, selecting the task in Project and then executing a copy on the selected task. Snippets of VBA code for doing that are shown below. Note that the SelectRow Method applies to the active Project view. The row is not necessarily the same as task ID. The row number will track the task ID only if the Project file is fully expanded and no filters or grouping is applied.

    If you are expecting to have VBA code automatically copy the selected task to the clipboard when a user clicks on the hyperlink, then I know of no way to do that with VBA since simply selecting a Project object does not raise any Events.

    John

    This code snippet opens a Project object:

    Dim Prj As MSProject.Application

    On Error Resume Next
    Set Prj = GetObject(, "MSProject.application")
    If Err <> 0 Then
        On Error GoTo 0
        Set Prj = CreateObject("MSProject.Application")
        If Err <> 0 Then
            MsgBox "MS Project is not available on this workstation" _
                & vbCr & "Install Project or check network connection", vbCritical, _
                "Excel to Project - Fatal Error"
            FilterApply Name:="all tasks"
            Set Prj = Nothing
            On Error GoTo 0     'clear error function
            Exit Sub
        End If
        
    End If
    On Error GoTo 0
    Prj.Visible = True

    This code snippet selects a specific row (in this case 13) and then copies it to the clipboard

    selectrow row:=13,rowrelative:=false,height:=0,extend:=false,add:=false
    editcopy

        


    Thursday, October 27, 2016 5:37 PM
  • John, thank you again for what you do. I have to many projects that include the production of different details, workpieces and other different components. To organize all information about this and calculate the production time I use installed on a separate server MS Project accessible to my supervisors and subordinates. When I write some reports or directives on specific tasks it is very convenient to attach a link to them to people could click and go directly to the right task and not look for it among different projects, and within the project among hundreds of other tasks in this project. So, I have no need to copy a specific task, I want to get only a hyperlink to it. Sorry for my English, if you have problems with understanding. I never used English in addition to the school lessons)
    Thursday, October 27, 2016 8:19 PM
  • I have found this solution. Is it correct? Sub Tester() Dim wdDoc, h, urlString, displayText Set wdDoc = ActiveDocument Set h = wdDoc.Hyperlinks.Add(Anchor:=Selection.Range, _ Address:=urlString, SubAddress:="", _ TextToDisplay:=displayText) h.Range.Copy
    Thursday, October 27, 2016 8:22 PM
  • GfiFer,

    Is it correct? My question to you is, does it do what you want? My guess is that it does not because the range being selected for copy is in the current Word document, not the Project task pointed to by the hyperlink. What gets copied to the clipboard is the text of the hyperlink, in this case whatever "displayText" says.

    If that's what you want to happen, then you are there, but I don't think that is what you want. What I believe you want is to copy the Project task line pointed to by the hyperlink and paste that to the clipboard. Re-read my last post. It explains what will and will not happen and also what you need to do to get what I think you want.

    You mentioned that Project is available to your users on a server. Do they access Project files using Project Web Access (PWA)?

    John


    Thursday, October 27, 2016 10:14 PM
  • Anyway, here's what I need but there is a small problem. When I click on the hyperlink, copied by this macro and pasted into MS Word, opens the right project, but task not selected. How can I fix it?

    Sub CopyLink_Project()
        Dim hLink As Object
        Dim wd As Object
        Dim appWd As Word.Application
        
        Dim SelectedItem As String
        Dim projPath As String
        Dim TaskName As String
        Dim TaskID
        Dim wdDoc
                    
        If ActiveSelection = 0 Then
            MsgBox ("Nothing selected")
            GoTo lbl_Exit
        End If
        
        If ActiveSelection.Tasks.Count > 1 Then
            MsgBox ("Too many selected")
            GoTo lbl_Exit
        End If
        
        TaskID = ActiveSelection.Tasks(1).UniqueID
        TaskName = ActiveSelection.Tasks(1).Name
        projPath = ActiveProject.FullName
    
        'Create temp Word doc
    
        Set appWd = CreateObject("Word.Application")
        Set wdDoc = appWd.Documents.Add
    
        Set hLink = wdDoc.Hyperlinks.Add(Anchor:=wdDoc.Range, _
            Address:=projPath, _
            SubAddress:="gantt chart!" + CStr(TaskID), _
            ScreenTip:="", _
            TextToDisplay:=TaskName)
             
            'text format
            hLink.Range.Font.Name = "Segoe UI"
            hLink.Range.Font.Size = 10
            hLink.Range.Font.Color = RGB(0, 0, 255)
    
        hLink.Range.Copy
        
        'clear
    lbl_Exit:
        Set hLink = Nothing
        Set wdDoc = Nothing
        Set wd = Nothing
        Set appWd = Nothing
        Exit Sub
        
    End Sub
    P.S. As for the PWA. Now it's just constantly running computer with remote desktop access.


    • Edited by GfiFer Friday, October 28, 2016 3:09 PM
    Friday, October 28, 2016 12:26 PM
  • Gfifer,

    i ran your macro in a simple Project test file. The results are shown in the screen shot below. I added a appWd.Visible=true statement to your code so so I could easily see the results.

    As you can see, everything works fine as far as creating the link and copying it to the clipboard. If I click on either link in Word (the original link or the pasted link), they both open the Project file and select the desired task.

    Question. When you click on the link in Word and Project is opened, what task is selected?

    The issue may be due to your use of a server based installation of Project. All my testing is with locally installed versions of Project and Word.

    John

    Friday, October 28, 2016 5:52 PM
  • I have tryed to debug this on my local computer and it not works

    When i open the Project there is selected the first task, as if I had opened the project from the icon. Seems that subaddress not works 

    Friday, October 28, 2016 6:22 PM
  • GfiFer,

    I think I found the problem. In your macro the TaskID variable saves the Unique ID value for the subaddress. It should save the ID.

    TaskID = ActiveSelection.Tasks(1).ID

    Try that and see if it works locally. If it does, then try it with Project on the server.

    John

    Friday, October 28, 2016 9:07 PM
  • I have changed this line in my code, but it not works locally again. Can you send your code, please?

    As i can see, ID and UniqueID is the same for my project

    • Edited by GfiFer Saturday, October 29, 2016 8:05 PM
    Saturday, October 29, 2016 7:57 PM
  • GfiFer,

    Actually it is your code but I cleaned it up a bit. Here is the process I used.

    1. Create a small Project test file with a few tasks

    2. Select one of the tasks and run the macro. The code will make Word visible

    3. Select a different task in the Project file and then activate Word

    4. Click on the hyperlink in Word. It should take you to the original selected task in the Project file.

    In a new unedited Project file, the ID and Unique ID will be the same. If tasks are moved around or added or deleted, the ID and Unique ID will no longer track each other. If the ID and Unique ID for a selected task are not the same and you use the UniqueID for the hyperlink subaddress, the code attempt to go to that ID. If that ID does not exist in the file, the first task in the file (ID=1) will be selected by default.

    John

    Option Explicit
    Sub CopyLink_Project()
        Dim hLink As Object
        Dim appWd As Word.Application
        Dim wdDoc As Word.Document
        Dim projPath As String
        Dim TaskName As String
        Dim TaskID As Integer
                    
        'check that at least one task but only one task is selected
        If ActiveSelection = 0 Then
            MsgBox ("Nothing selected")
            Exit Sub
        ElseIf ActiveSelection.Tasks.Count > 1 Then
            MsgBox ("Too many selected")
            Exit Sub
        End If
        
        TaskID = ActiveSelection.Tasks(1).ID
        TaskName = ActiveSelection.Tasks(1).Name
        projPath = ActiveProject.FullName

        'Open Word and create new document
        Set appWd = CreateObject("Word.Application")
        Set wdDoc = appWd.Documents.Add
        appWd.Visible = True

        Set hLink = wdDoc.Hyperlinks.Add(Anchor:=wdDoc.Range, _
            Address:=projPath, _
            SubAddress:="gantt chart!" + CStr(TaskID), _
            ScreenTip:="", _
            TextToDisplay:=TaskName)
             
            'text format
            hLink.Range.Font.Name = "Segoe UI"
            hLink.Range.Font.Size = 12
            hLink.Range.Font.Color = RGB(0, 0, 255)

        'copy that link to the clipboard
        hLink.Range.Copy
        
        'all done, clean up and close
        Set appWd = Nothing
        
    End Sub

    Saturday, October 29, 2016 11:00 PM
  • I have tryed your code, but it not works with my Project. The first task selected again. Maybe I need to enable something in the Project settings?
    • Edited by GfiFer Sunday, October 30, 2016 12:48 PM
    Sunday, October 30, 2016 12:46 PM
  • If one were to use not #gantt chart!ID in subaddress, and anything else? For example #task!ID..

    I tried several variations but it didn't work. Maybe you know the correct syntax?

    Sunday, October 30, 2016 1:47 PM
  • GfiFer,

    A hyperlink selects a particular location in a Project view. That's why it needs the ID rather than the Unique ID. The Gantt Chart is a specific view in Project so yes, you could use some other view. For example, you could use #resource sheet!5. In that case the link will open Project and select resource ID 5 on the Resource Sheet view. Your example #task!ID is not a view however #task sheet!ID would work because the Task Sheet is a view.

    You say you tried several variations but it didn't work.

    1. Are both Project and Word local on your PC?

    2. What versions of Project and Office are you using?

    3. Are those versions fully updated?

    4.When you say it didn't work what does that mean?

      a. Did it or did it not create a hyperlink in Word?

      b. If it did create a link can you show a screen shot of that link and the Project test file (similar to the screen shot I showed in my forum response on Friday)?

      c. When you click on the link, what happens (does it open Project)?

      d. If it does open Project, what is the view name?

      e. What ID is selected?

    Something else to consider. If the Project file was filtered or grouped when it was last saved and the task ID called out by the hyperlink was not visible, the hyperlink will not be able to select it and will therefore default to the first task line in the visible file (normally task ID 1).

    In your response on Wednesday, October 26, you said the code I provided actually worked. What code was that and how exactly did you run it?

    If I may ask, where are you located (country)?

    John

    Sunday, October 30, 2016 3:57 PM
  • Oh, I meant a slightly different meaning

    1. Yes, both program on my PC

    2. I use MS Word 2016 and MS Project 2013

    3. I use autoupdate and hope that it fully updated

    4. It select right ID and create correct hyperlink that opens project when click, but MS Project allways select the first task in project, even when i created one by one your screen project. I'll try to use #task sheet!ID, and tell about results.

    Yes, when i tryed to create those link by means of Outlook code on Wednesday, October 26 it was worked! But now it not works

    I am in Moscow, Russia.

    Sunday, October 30, 2016 4:42 PM
  • With the #task sheet!ID at opening only the first task selected. I have the feeling that Project simply ignores the subaddress
    Sunday, October 30, 2016 4:51 PM
  • GfiFer,

    Okay, so you are on the other side of the world, I'm in USA.

    Thank you for the information about you setup. The problem may be due to using different versions of Project and Office. See the following post and blog

    https://answers.microsoft.com/en-us/msoffice/forum/msoffice_project-mso_win10/incompatibility-between-project-2013-and-office/c421313e-a872-4754-bdfb-5a052bdc23cd

    https://blogs.technet.microsoft.com/projectsupport/2015/09/23/project-2016-should-i-upgrade

    There are so many different installation configurations now it makes one's head spin (i.e. confusion). All my testing was done with Office 2010 and Project 2010. I don't have later versions so I cannot tell you if it will work with later versions or even mixed versions. My guess is that is does not work with mixed versions and your results seem to confirm that.

    What type of installations do you have, MSI, click-to-run, or subscription (365)? I may be able to find some help from someone who has the same configuration as you do.

    John

    Sunday, October 30, 2016 5:45 PM
  • I have long realized that we're pretty far away because we have very different activity time) I'll carefully read posts and blog, I hope it will be helpful. What about my type of installations. Ofice was preinstalled when I bought my PC and it not 365 version. Project I installed at work on a volume license from CD. What is it "click-to-run"? First heard about it.
    But i still can't understand why it works when i was try it with Outlook hyperlinks? But now it not works too. To be honest, i could not switch the task or not close the project and it seems that all right.
    • Edited by GfiFer Sunday, October 30, 2016 6:52 PM
    Sunday, October 30, 2016 6:42 PM
  • GfiFer,

    If Office was pre-installed on your computer then I suspect it is equivalent to MSI (MicroSoft Installer). The same would be true if you installed Project from a CD. That would use the Microsoft installer, so at least you have the same installation process for both Office and Project.

    Click-to-run is a new streaming type of installation process that allows faster startup.

    Let's get back to your Outlook hyperlink testing. In that macro everything is done in Outlook. In other words the macro doesn't hyperlink between two separate applications, (i.e. Word and Project), it works totally within Outlook so it works fine. Did you ever get a macro to create a working hyperlink between two different applications?

    Here are some tests that will help isolate where the problem is occurring for you. The first part will attempt to manually create a hyperlink between Office 2016 and Project 2013. The second part will attempt to manually create a hyperlink completely within Office 2016 with no Project 2013 involved.

    First Part:

    1. In a Word document click on Insert Hyperlink.

    2.When the Edit Hyperlink window appears, select an existing Project file in the current folder.

    3. When the address appears, edit it by adding the subaddress #gantt chart!5 (or some other ID value that will not be hidden if the Project were opened manually)

    4. Now click on the link created. Does it go to the Project file and does it go to task ID 5?

    Second Part:

    5. If that doesn't work, close Project and select an existing Excel workbook on your local drive. Open it and make a note of the worksheet name. Then close the workbook.

    6. Go back to Word and click on Insert Hyperlink.

    7. Edit the path by adding the subaddress #sheet1!B2 (if the worksheet is still named "sheet1", otherwise use the actual worksheet name)

    7. Now click on the link created. Does it go to the Excel worksheet and select range B2?

    John

    Sunday, October 30, 2016 10:49 PM
  • Oh, what about Outlook. I have meant that I used Outlook macro, but when create hyperlink inserted something like: wdDoc.Hyperlinks.Add Anchor:=Selection, Address:= _ "C:\Users\John\Documents\Planning.mpp", SubAddress:= _ "gantt chart!13", TextToDisplay:= _ "C:\Users\John\Documents\Planning.mpp#gantt chart!13" So after copying this I inserted hyperlink into MS Word and tryed to oped project by means of this link. And it was worked and right task was selected! But if i doing this now, it select just first task. What about testing First part: those link opens right project, but first task selected again. Second part: Excel opens and B2 range is selected! So, it works with Excel Today I tryed to ran our macro with MSI Ofice 2016 and MSI Project 2016, but it select first task when open.
    Monday, October 31, 2016 4:35 PM
  • GfiFer,

    I'm a little confused by your sentence that reads, "So after copying this I inserted hyperlink into MS Word and tryed to oped project by means of this link. And it was worked and right task was selected! But if i doing this now, it select just first task". Are you saying it worked the first time but not the second time?

    Please provide a screenshot of the Word 2016 hyperlink and a screenshot of the Project 2016 file would help also (similar to the screenshot I showed in my response last Friday).

    John

    Monday, October 31, 2016 5:15 PM
  • So, I thought it worked October 26th. But it is possible, that with a project open and not first task selected I clicked on the link in Word and have the impression that the desired task selected. I will provide screenshots at the same time, as I can confirm my account. I have a small problem with email
    Monday, October 31, 2016 8:12 PM
  • GfiFer,

    I understand. I also have been "fooled" by test results that I thought showed a particular outcome but in fact, the outcome was different or misleading due to poor control of my test. Do feel alone.

    Normally a new user's account is verified after a period of time, but the process can be expedited. See the following article:

    https://social.technet.microsoft.com/Forums/en-US/338e5c21-c7e3-4519-8791-f819535be481/verify-your-account-36?forum=reportabug

    John

    Monday, October 31, 2016 8:48 PM
  • John, i have an idea, and i need your help. So, with Outlook i was create hyperlink like:

    wdDoc.Hyperlinks.Add(Anchor:=Range, _ 
            Address:="outlook:" + olItem.EntryID, _ 
            SubAddress:="", _ 
            ScreenTip:="", _ 
            TextToDisplay:="linkName") 

    And in facts, in address i have some like "outlook:HBSDLVBDFV-DFBDFB-DBDFZBDFBDFB" and if click on this link in Word then Outlook opens my olItem. 

    Can i create the same hyperlink with something like:

    wdDoc.Hyperlinks.Add(Anchor:=Selection.Range, _
            Address:="project:" + ActiveSelection.Tasks(1).Guid, _
            SubAddress:="", _
            ScreenTip:="", _
            TextToDisplay:=TaskName)

    or try another method with Guid? 


    • Edited by GfiFer Tuesday, November 1, 2016 3:12 PM
    Tuesday, November 1, 2016 3:12 PM
  • GfiFer,

    I don't know but I doubt it. In a hyperlink the Address argument is a path to a target document and the SubAddress argument is a specific location in that target document. If you try to combine the location with the path you will get an error message saying the hyperlink can not find the file.

    Furthermore, the Guid is similar to the Unique ID in Project and we already tried using the Unique ID as the subaddress without success.

    What about the screen shots I asked for? We need to find out why it works for me using Office 2010 and Project 2010 but doesn't work for you using Office 2016 and Project 2016 and the only way I can do that is to get enough information so I can ask for help from someone who has Office 2016 and Project 2016 and has more knowledge about hyperlinks than I do.

    John

    Tuesday, November 1, 2016 4:17 PM
  • Can you provide your email address to I will be able to send you the screenshots? I promise to spam not too often)
    Tuesday, November 1, 2016 8:36 PM
  • GfiFer,

    See below

    John

    jensenljatatfastmaildotdotfm

    (remove obvious redundancies and the 7th character is a letter)

    Tuesday, November 1, 2016 10:23 PM
  • I have send screenshots. Please, check your mailbox
    Wednesday, November 2, 2016 7:22 PM
  • GfiFer,

    Your message indicates you sent it an hour and a half ago and I have not received anything. You mentioned that you were having trouble with your e-Mail a couple of days ago. Are you sure your e-mail is working?

    John

    Wednesday, November 2, 2016 8:55 PM
  • It was enother problem. I lost my password. 

    Can you send me test message to kps2209 @ mail . ru ?

    Thursday, November 3, 2016 7:04 AM
  • GfiFer,

    If you meant to say "text" message then sorry I can't do that. I don't text. I did send an e-mail to the address you gave but don't know if that will work.

    John

    Thursday, November 3, 2016 3:08 PM
  • To those who may follow this thread,

    I did contact the poster and worked with him directly via e-mail. I am happy to report the issue is resolved and I'm posting this message to summarize the result for the benefit of other users who may have a similar issue.

    Background:

    Gfifer wanted to create a hyperlink in a Word document such that those reading the document could click on the link and it would open a Project file to a specific task line. He wanted to do it with VBA. To do that we used the VBA code in my October 29, 2016 response earlier in this thread. We also created a hyperlink manually from Word and using a simple macro directly in Word.

    The result and problem:

    When I ran the test using an English version, the hyperlinks always worked fine. The Project file opened and the desired task was selected. Myself and two others verified correct operation with Project/Office 2010, Project/Office 2013 and Project/Office 2016. However when Gfifer, who was using a Russian version of Project/Office 2016, ran the macro or set up the link manually, the hyperlink from Word opened the Project document but it did not select the desired task line, it always selected the first task.

    The solution:

    The line of code in the macro that creates the subaddress part of the hyperlink (i.e. to select the desired task) is:

    SubAddress:="gantt chart!" + CStr(TaskID), _

    It specifies the desired view and task ID. For English versions "Gantt Chart" (or any other view name) are in English. However, in Russian, and perhaps other languages, view names are stored in the language being used, in this case, Russian. Once Gfifer changed the subaddress to call out the Russian equivalent for "Gantt Chart", the Project file opened AND the desired task was selected.

    SubAddress:= "диаграмма ганта!" + CStr(TaskID), _

    My thanks to Vadim Bogdanov, Office Solutions MVP for his assistance in finding the answer.

    John

    Monday, November 14, 2016 9:02 PM