excelvbaformssharepointuserform

VBA Excel "Compile error: duplicate declaration" only on certain machines in shared workbook


Ive been working on a data entry form to input lines in a delivery plan in excel. After many manual tests and a few modules to run primitive unit tests, i got it working flawlessly on my local prototype .xlsm workbook. Below is an example of the form and a github repo containing the vba code.

Github repo of NDA safe example data and VBA code

enter image description here

After uploading it to sharepoint and testing it again, no problems appeared for myself. When i then released it to my colleages, one of them ended up with a "duplicate declaration" compilation error. This error somehow cascaded across machines, bricking the code to open the form, untill i replaced the form module with a backup. The form opens and works, with no problem, on all other computers ive tested it on.

The debugger points me to clsLeveringsPlanForm.show in modFormShowerButton.bas as the duplicate declaration. Trying to fix this by defining the form as an instance of clsLeveringsPlanForm, then using that instance results in the "Private frm As clsLeveringsPlanForm" as duplicate declaration. The weird thing is that im able to run the form on multiple other computers at the same time, but not after his run.

Attribute VB_Name = "modFormShowerButton"
' ========= modFormShowerButton.bas =========
Option Explicit


Public Sub Show_New_Line_Form()
    clsLeveringsPlanForm.Show vbModeless
    Call RefreshMasterProductList
End Sub

Sadly im not able to reproduce the error on a local copy, but theres one stored in the github repo. If i am missing some crucial information about forms always breaking because of concurrent editing, version differences or any other hints, i would greatly appreciate the help. :)


Solution

  • I was able to reproduce the “Duplicate definition” error with the file BARNDOMSFEJL 140825.xlsm and successfully fixed it on my computer. Here’s what I did:

    1. Removed the form clsLeveringsPlanForm from the project.

    2. Cleared the code in clsLeveringsPlanForm.frm starting from Option Explicit (leaving the definitions intact).

    3. Re-imported the modified clsLeveringsPlanForm.frm.

    4. Manually re-added the code to the form.

    After these steps, the error disappeared. I’m not certain if this will work on your system

    Update: I think I got a bit closer to the the culprit. You have got a frame on your form with the name fraGauge and in the code of your form you have got the line

    Private WithEvents fraGauge As MSForms.Frame    ' ensure your frame is named fraGauge
    

    So, it seems, after all, the error message is correct. As soon as I remove this line and leave everything else as it is all works fine.

    PS What is the line good for anyway? IMHO as you have a frame on your form with the name fraGauge you don’t need to (and must not) redeclare it with Private WithEvents
    Interestingly, you can add the line above, run Debug/Compile, and execute the code without any errors. However, as soon as you close and reopen the file, you encounter the error message Duplicate definition.