IguanaTex icon indicating copy to clipboard operation
IguanaTex copied to clipboard

Run-time error "5" Invalid procedure call or argument

Open nmgzjf opened this issue 2 years ago • 16 comments

I have installed IguanaTex following the instructions on the M1 MacBook Pro (14-inch, 2021). AN ERROR WILL APPEAR when I click any button in the "Main Settings" window. The error message is 'Visual Basic for Applications: Run-time error "5" Invalid procedure call or argument'. 1 2 How can I solve this problem?

nmgzjf avatar Sep 02 '23 13:09 nmgzjf

Which installation did you use, manual or homebrew? Maybe try the other one. Can you use the New LaTeX display button?

Jonathan-LeRoux avatar Sep 23 '23 23:09 Jonathan-LeRoux

I have tried both methods, and the above situation will appear. When I click the New LaTeX display button, the window will appear. However, when I click the Generate button, the error will appear.

nmgzjf avatar Oct 04 '23 03:10 nmgzjf

What version of PowerPoint are you using?

If you could unload the addin and instead open the .pptm file and run the macros in its Iguanatex tab, then you may have the option to debug when the error occurs, which could help us pinpoint where things go wrong.

Jonathan-LeRoux avatar Oct 05 '23 03:10 Jonathan-LeRoux

I get the same error on Windows when I try to convert an equation to vector. Everything else seems to work. Also, version v1_58 does not have this problem, but is A LOT slower in the conversion.

As you suggested, I opened the .pptm of 1_60_3 and then got a "Debug" button. Microsoft Visual Basics opens with a bunch of windows. The code shown is

Public Sub ConvertToVector()
    Load BatchEditForm
    BatchEditForm.CheckBoxModifyBitmapVector.value = True
    BatchEditForm.ComboBoxBitmapVector.Enabled = True
    BatchEditForm.ComboBoxBitmapVector.ListIndex = 1
    BatchEditForm.CheckBoxModifyPreserveSize.value = True
    BatchEditForm.CheckBoxForcePreserveSize.Enabled = True
    BatchEditForm.CheckBoxForcePreserveSize.value = True
    BatchEditForm.ButtonRun_Click
End Sub

Where BatchEditForm.ButtonRun_Click is highlighted and got an arrow on its left.

AstanVizu avatar Dec 09 '23 17:12 AstanVizu

The error must been happening inside that function. Could you "step into" (F8) that function then keep "stepping over" (Shift+F8) until you hit the error? If the error happens at yet another function call, you'll need to "step into" again, etc., until you find the line that actually causes the problem.

Jonathan-LeRoux avatar Dec 10 '23 17:12 Jonathan-LeRoux

So it seems that the error is in the following function:

Public Function convertSVG(inSh As Shape, ByVal ScalingX As Single, ByVal ScalingY As Single, _
                           Optional ByVal posX As Long = -1, Optional ByVal posY As Long = -1) As Shape
    With inSh
        .ScaleHeight 1#, msoTrue
        .ScaleWidth 1#, msoTrue
        .LockAspectRatio = msoFalse
        .ScaleHeight ScalingY, msoTrue
        .ScaleWidth ScalingX, msoTrue
        .LockAspectRatio = msoTrue
    End With
    ' Because we're applying a ribbon function, we need to use selection to keep track of the shape
    Dim Sel As Selection
    inSh.Select
    Call CommandBars.ExecuteMso("SVGEdit")
    Set Sel = Application.ActiveWindow.Selection
    Dim NewShape As Shape

where Call CommandBars.ExecuteMso("SVGEdit") is highlighted. If I do F8 or Shift+F8, I hit the error.

AstanVizu avatar Dec 11 '23 20:12 AstanVizu

I'm guessing your version of Powerpoint does not support SVG.

  • If you try to insert an SVG file in your presentation via the "Insert" tab in the ribbon (then "Pictures">"This device..." for example), does that succeed?
  • If it does, can you try to go to the "Graphics Format" tab and see if you have a "Convert to Shape" button in the ribbon?

I need to better handle this. Could you try to modify the code as follows?

    Dim Sel As Selection
    inSh.Select
    On Error Resume Next
    Call CommandBars.ExecuteMso("SVGEdit")
    On Error GoTo 0 
    Set Sel = Application.ActiveWindow.Selection
    Dim NewShape As Shape

The code should run without error. The downside is that it will silently do nothing, leaving the SVG as a Graphics object (same as just inserting via the "Insert" menu) instead of converting it to a Shape object. Another option would be to display a message saying "Your Powerpoint version appears not to have full SVG support, the file will be inserted as a Graphics object without being converted to a Shape".

Jonathan-LeRoux avatar Dec 11 '23 20:12 Jonathan-LeRoux

Thanks a lot for your patience. Indeed I can insert an SVG, but I cannot find the "Convert to Shape" button. I'm using Microsoft Office Professional Plus 2016. However, after opening the relevant code through "Debug" on the error, I insert the On Error GoTo 0 line, but I still get the same error when re-running everything. Again the line Call CommandBars.ExecuteMso("SVGEdit") is highlighted.

AstanVizu avatar Dec 12 '23 17:12 AstanVizu

Could you try the .pptm file in IguanaTex_v1_61_beta2.zip?

It should still insert the SVG but will display a box saying the object wasn't converted to Shape. If this works, I could add a "Never show this again" checkbox, so that the box no longer appears. I don't think IguanaTex adds much if anything over the simple "Insert SVG" feature of PowerPoint though.

Jonathan-LeRoux avatar Dec 13 '23 16:12 Jonathan-LeRoux

I tried your beta version and indeed there is no error anymore but instead it gives the box with the warning. However, unfortunately, this is basically unusable, because the shape and size of the result is completely off and some parts of equations, most notably the slash for fractions, are missing.

AstanVizu avatar Dec 18 '23 08:12 AstanVizu

Could you send me an example of SVG file that fails?

Jonathan-LeRoux avatar Dec 18 '23 09:12 Jonathan-LeRoux

Hi, I wanted to chime in that I'm getting this exact same error using PowerPoint 2016 on Windows 10 when I try to generate any LaTeX display. It appears to be some sort of issue with the SVG generation, since it shows up in every version of IguanaTex since 1.6. Strangely, the LaTeX display is still generated, but IguanaTex doesn't recognize it as a display so I can't interact with it after generating.

williamdwarke avatar Dec 19 '23 04:12 williamdwarke

Could you send me an example of SVG file that fails?

Here is your new version, where I put an equation on the front page:

IguanaTex_v1_61_edit.zip

So what I did is copy paste an equation (\frac{1}{2}) from another file onto the front page and then try to re-generate it as a shape. The result is that the box of the equation is way too large and the slash in the fraction is missing.

AstanVizu avatar Dec 19 '23 06:12 AstanVizu

I had forgotten that this function also gets used when creating a Shape (formerly Vector) display, so that can create all sorts of problems.

I will do more tests and see if it is viable to leave SVG as an option for us on Office 2016. In the meantime, I recommend switching to EMF in the Main Settings.

Jonathan-LeRoux avatar Dec 21 '23 05:12 Jonathan-LeRoux

Hi Jonathan, I did end up switching back to EMF and it seems to be working now. Thanks for the input!

williamdwarke avatar Dec 21 '23 23:12 williamdwarke

@AstanVizu I think you're hitting a separate issue reported in https://github.com/Jonathan-LeRoux/IguanaTex/issues/45 and https://github.com/Jonathan-LeRoux/IguanaTex/issues/22#issuecomment-972287547, due to the use of PDF as intermediate step for SVG conversion ("SVG via PDF w/ dvisvgm"). If you use "SVG via DVI w/ dvisvgm", things should be better.

I realized that the use of SVG files not converted to Shape is not ideal, however. Some parts of the display can be hidden, for example the bottom is cut in the bottom display below (top: SVG converted to Shape; bottom: no conversion): image

So I'm not sure I should let users create such displays, as they may not realize that the displays are not perfect. One option is to include a clear warning in the message box. Another is to simply disable SVG conversion.

Jonathan-LeRoux avatar Dec 25 '23 12:12 Jonathan-LeRoux

Closing this issue as it is now "fixed" (as in, "handled properly") in Release v1.61.

Jonathan-LeRoux avatar Mar 28 '24 02:03 Jonathan-LeRoux