locked
IMPORTING VBA MODULES IN WORD 2010 RRS feed

  • Question

  • I am trying to write some modular code for my company so that I do not have to constantly add the same code to my macros.  In this case, I need to pull the name of a county from our database.  The GetCounty module does that but when I try to compile this macro, I get this "COMPILE ERROR: Sub or Function not defined".  My code is below

    Sub AutoOpen()
    '
        Application.VBE.ActiveVBProject.VBComponents.Import "U:\Jason Bennett\Work\Macro Files\clsDatabase.cls"
        Application.VBE.ActiveVBProject.VBComponents.Import "U:\Jason Bennett\Work\Macro Files\GetCounty.bas"

    ' Declaring variables.
        Dim strFileNumber As String

    ' Getting the file number.
        strFileNumber = InputBox("What is our file number? XX-XXXXX.", "FILE NUBMER")

    ' Calling the function to get the county name.
        strCounty = Get_County(strFileNumber)
        MsgBox "The county is " & strCounty, vbOKOnly, "COUNTY NAME TEST"

    ' Removing the modules.
        Application.VBE.ActiveVBProject.VBComponents.Remove

    End Sub

    Any help would be greatly appreciated.

    Monday, May 16, 2011 9:48 PM

Answers

All replies

  • What line is the error on?
    Maybe Get_County() is not defined?
     
     
    "LorrdWolf" <=?utf-8?B?TG9ycmRXb2xm?=> wrote in message
    news:db46b589-9dc8-407c-9a21-404bd195d70f...
    I am trying to write some modular code for my company so that I do not have
    to constantly add the same code to my macros. In this case, I need to pull
    the name of a county from our database. The GetCounty module does that but
    when I try to compile this macro, I get this "COMPILE ERROR: Sub or Function
    not defined". My code is below
    Sub AutoOpen()
    '
    Application.VBE.ActiveVBProject.VBComponents.Import "U:\Jason
    Bennett\Work\Macro Files\clsDatabase.cls"
    Application.VBE.ActiveVBProject.VBComponents.Import "U:\Jason
    Bennett\Work\Macro Files\GetCounty.bas"
    ' Declaring variables.
    Dim strFileNumber As String
    ' Getting the file number.
    strFileNumber = InputBox("What is our file number? XX-XXXXX.", "FILE
    NUBMER")
    ' Calling the function to get the county name.
    strCounty = Get_County(strFileNumber)
    MsgBox "The county is " & strCounty, vbOKOnly, "COUNTY NAME TEST"
    ' Removing the modules.
    Application.VBE.ActiveVBProject.VBComponents.Remove
    End Sub
    Any help would be greatly appreciated.
     
     
    Wednesday, May 18, 2011 2:23 PM
  • For a general discussion on code importation, including code samples see: http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/6754e433-41aa-42fd-ad28-07653d8f580b


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by Sally Tang Friday, May 20, 2011 8:45 AM
    Thursday, May 19, 2011 1:58 AM