PlantUML_Template_v30 does not work

0 votes
asked Jan 11, 2016 in Bug by nbrio (120 points)
edited Mar 1, 2016 by nbrio

I installed the Word template v30 according to the instructions it contains (putting the tempate in %appdata%\Microsoft\Word\STARTUP). I also installed the plantuml.jar and Graphviz as instructed.

When I start word every time I get an error "The macro cannot be found or has been disabled because of your Macro security settings". The error always shows twice. In my Macro security settings macros are set to always enabled.

I use Windows 10 and Word 2013 x64. I am logged in as an administrator. I tried the Word template v27, but with the same result.

When I open the Visual Basic the project cannot be compiled due to multiple compilation errors.

Can anyone help me?

2 Answers

0 votes
answered Aug 8, 2016 by anonymous
Same for me.

In my case, windows defender deleted the template by trojan alert

:(
0 votes
answered Mar 17, 2017 by anonymous

Hey there.

I am using the Word-Add-In as well and its working fine. A colleague of mine wanted to start the Add-In yesterday (both PCs Windows 7, Word 2010). It failed with the error described above. We decided to have a look at what is going on and found an issue in the code base that resolves the execution path. I will put the needed stuff here and then inform the team. Hope this works as I am not familiar with the process on this site.

So, if you remove the template from the folder %appdata%\Microsoft\Word\STARTUP and copy it to somewhere you can open the template and are able to use the developer tools to look into the VBA code. In Module PlantUML go to function getExePath (used by getJarPath and by getDotPath). If you have a new document there the mainPath variable starts with an empty string. Afterwards the search starts and if you accidentically have the plantuml.jar in your current directory, the file is found and the resulting mainPath which is then returned is the empty string. The calling method getJarPath interprets this as not finding the file and you end up with a message box stating the error "Error : Cannot find plantuml.jar in : ...".

So, the general solution could be to remove the plantuml.jar from your default current directory. But in my opinion this should be stable working hence, we made an own version (I must look to reference it here somewhere and will do so, but put down changes here). For this we took the function getExePath and added the following lines of code between the lines 111 and 113 of the method:

    ' In case mainPath is the empty string as the active document is the empty string,
    ' and in case the plantuml.jar can be found in the current directory, the below
    ' code results in mainPath being the empty string which would work properly if
    ' the calling method would not check for an empty string as execution path
    ' and state this is wrong and has to fail. Therefore, change main path in case
    ' it is an empty string at this point with an explicit, not empty string stating to
    ' use the current folder as relative path.
    If mainPath = "" Then
        mainPath = ".\"
    End If
 
The comment is lengthy but I put it down to prepare giving the code back to the people here.
 
This fixed our issues. Hope it helps.
 
Cheers,
 
Andreas

 

 
 
 
 
commented Apr 21, 2017 by plantuml (294,960 points)
Ok, thanks for the fix.
We are going to release a new version of the Word Template.
Could you confirm that the patched function would be:

Function getExePath(searchfor As String, ByRef try As String) As String
    Set fs = CreateObject("Scripting.FileSystemObject")
     
    nbTemplates = ActiveDocument.Parent.Templates.Count
    mainPath = ActiveDocument.Path
    
    ' see http://plantuml.sourceforge.net/qa/?qa=4083/plantuml_template_v30-does-not-work
    ' In case mainPath is the empty string as the active document is the empty string,
    ' and in case the plantuml.jar can be found in the current directory, the below
    ' code results in mainPath being the empty string which would work properly if
    ' the calling method would not check for an empty string as execution path
    ' and state this is wrong and has to fail. Therefore, change main path in case
    ' it is an empty string at this point with an explicit, not empty string stating to
    ' use the current folder as relative path.
    If mainPath = "" Then
        mainPath = ".\"
    End If
    
    try = ActiveDocument.Path & "\"
    
    nb = InStrRev(mainPath, "\")
    Do While nb > 1 And fs.FileExists(mainPath + searchfor) = False
        mainPath = Left(mainPath, nb - 1)
        try = try & vbCrLf & mainPath & "\"
        nb = InStrRev(mainPath, "\")
    Loop
    
    For I = 1 To nbTemplates
        If fs.FileExists(mainPath + searchfor) = False Then
            mainPath = ActiveDocument.Parent.Templates.Item(I).Path
            try = try & vbCrLf & ActiveDocument.Parent.Templates.Item(I).Path & "\"
            nb = InStrRev(mainPath, "\")
            Do While nb > 1 And fs.FileExists(mainPath + searchfor) = False
                mainPath = Left(mainPath, nb - 1)
                try = try & vbCrLf & mainPath & "\"
                nb = InStrRev(mainPath, "\")
            Loop
        End If
    Next I
    
    If fs.FileExists(mainPath + searchfor) Then
        getExePath = mainPath
    Else
        getExePath = "Error : Cannot find plantuml.jar in :" & vbCrLf & try
    End If
    
    
End Function
commented Apr 25, 2017 by anonymous
Hi together and sorry for the late answer.
As you are requesting to confirm the code here, I suppose you did not get my email (I used the contacts to send you the adopted file including the macro).
But, to answer your request. No, the code I have and we tested here is little different. I post it below. The given code lines are only little bit different in order. This is because of the first Do-While-Loop. Aim was to change as less logic of the existing code as possible. The first look-up loop works fine even if mainPath is empty. The problem arises in case the For -Loop. If the if-condition evaluates

If fs.FileExists(mainPath + searchfor) = False Then

to true, there is actually nothing done at all and finally an empty string is returned. I suppose the whole check in the method could be improved but had not enough time here to dig deeper, hence, I just made that quick fix for this case and the if-condition.
The final code of the method we currently use looks like this:


Function getExePath(searchfor As String, ByRef try As String) As String
    Set fs = CreateObject("Scripting.FileSystemObject")
     
    nbTemplates = ActiveDocument.Parent.Templates.Count
    mainPath = ActiveDocument.Path
    try = ActiveDocument.Path & "\"
    
    nb = InStrRev(mainPath, "\")
    Do While nb > 1 And fs.FileExists(mainPath + searchfor) = False
        mainPath = Left(mainPath, nb - 1)
        try = try & vbCrLf & mainPath & "\"
        nb = InStrRev(mainPath, "\")
    Loop
    
    ' In case mainPath is the empty string as the active document is the empty string,
    ' and in case the plantuml.jar can be found in the current directory, the below
    ' code results in mainPath being the empty string which would work properly if
    ' the calling method would not check for an empty string as execution path
    ' and state this is wrong and has to fail. Therefore, change main path in case
    ' it is an empty string at this point with an explicit, not empty string stating to
    ' use the current folder as relative path.
    If mainPath = "" Then
        mainPath = ".\"
    End If
    
    For I = 1 To nbTemplates
        If fs.FileExists(mainPath + searchfor) = False Then
            mainPath = ActiveDocument.Parent.Templates.Item(I).Path
            try = try & vbCrLf & ActiveDocument.Parent.Templates.Item(I).Path & "\"
            nb = InStrRev(mainPath, "\")
            Do While nb > 1 And fs.FileExists(mainPath + searchfor) = False
                mainPath = Left(mainPath, nb - 1)
                try = try & vbCrLf & mainPath & "\"
                nb = InStrRev(mainPath, "\")
            Loop
        End If
    Next I
    
    If fs.FileExists(mainPath + searchfor) Then
        getExePath = mainPath
    Else
        getExePath = "Error : Cannot find plantuml.jar in :" & vbCrLf & try
    End If
    
    
End Function


Hope this helps to clarify things. If I can give you some additional info, let me know.

Cheers,

Andreas
commented Apr 25, 2017 by plantuml (294,960 points)
Sorry, we did not get your email: it's very possible that the mail was automatically removed because it contains a word macro (Mail server looks this as suspicious mail)

Anyway, thanks for the feedback.
So we've just fixed the last word template with your modifications.
http://sourceforge.net/projects/plantuml/files/PlantUML_Template_v32.dotm/download

We have also set up a new repository for the word template
https://github.com/plantuml/word-template

We have extracted the VBA modules, so that people could push/pull code from GitHub.

Thanks again!
commented Apr 26, 2017 by anonymous
Hi again.
Sounds great! Thanks again for YOUR WORK! I think you do a great job.
About the mail: Sorry, I just throw it out into the net and did not think about the macro. It's normal such files get removed.

Cheers,

Andreas
...