Results 1 to 3 of 3

Thread: Compile error: Variable Not Defined

  1. #1

    Compile error: Variable Not Defined

    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi there, I've come across a most frustrating issue recently (using Excel 2007) regarding named ActiveX controls that reside on a Worksheet. Everything compiles and runs perfectly on my PC (Windows 7 32-bit/Office 2007) The file(s) in question are .XLS files, and when opened on another PC (Windows 7/Office 2007) as soon as the macros are enabled, it immediately opens the VBA code window up with one of my control names highlighted (e.g. "txtLName1") and shows the error message "Compile error - Variable Not Defined."

    I have hunted and hunted for potential solutions, but none that I found worked for me...does ~anybody~ here have any idea how I can fix this? Any help whatsoever would be greatly appreciated!!

  2. #2
    Magician NoS's Avatar
    Join Date
    Jan 2013
    British Columbia
    Excel Version
    Excel 2010
    You would probably have a better chance of answers if you were to post the procedure's code and give us an idea of what you've tried that hasn't fixed the situation.

  3. #3
    Procedure Code:
    Public Sub InitBackDoorControls()

    txtLName1.Visible = True ' Where highlight appears in context of error message
    txtLName1.Text = ""

    txtFName1.Visible = True
    txtFName1.Text = ""

    cbxPlan.Visible = True
    Call ShowPlanList

    chkFrzOnly.Visible = True
    chkFrzOnly.Value = False

    cbxFullOrSplit.Visible = True
    Call ShowFullOrSplitList

    lblPart.Caption = 1

    cbxNumDeliveries.Visible = True
    Call ShowNumDeliveriesList

    cbxHasCP.Visible = True
    Call ShowHasCPList


    Range("COST_RATE") = ""

    cmdLoadFromFile.Visible = False

    End Sub

    The issue appears to be the fact that somehow, on a PC other than the one I am working on (where everything works just fine), the names of the ActiveX controls which reside on the Worksheet are being reset to default names i.e. "CommandButton1", "TextBox1" etc...and in that light, the code referencing the control by it's assigned name will trigger the error "Variable not defined." The "Option Explicit" statement seems to make no difference whatsoever.

    I have tried deleting *.exd files from %Temp% directories on client suggested by Microsoft, and still to no avail!!!

    If you need more info from me, please advise...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts