+ Reply to Thread
Results 1 to 10 of 10

Getting error user define type not define

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Getting error user define type not define

    Hello Friends,
    I'm getting error 'Compile error: User-define type not define' in my program. Please remove it to run the program.
    Please also suggest me a code to minimise outlook after opening.
    Thanking you in anticipation.

    Mukesh
    Attached Files Attached Files
    Last edited by mukeshbaviskar; 08-25-2013 at 04:59 AM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Getting error user define type not define

    For your problem, in the Visual Basic Editor (VBE), select Tools > References > Microsoft Outlook 14.0 Object Library > OK. Obviously, the 14.0 should be changed if not Outlook 2010.

    I suggest making example workbooks that only show what you need help with. Try to make it simple and short.

    The recorder only gets you so far. Consider change code like:
    Range("A1").Select
    Selection.Clear
    use
    Range("A1").Clear
    Another tip: always use Option Explicit as the first line of code in an object like Module. You can make that a default option in VBE's Tools > Options > Require Variable Declaration > OK.

    You do not need to create several Modules with one Sub per Module. You can have many Subs and Functions in a single Module. I tend to create categories of Modules. e.g. mFSO, mKen, mOutlook, mMSWord, mWorkbook, mWorksheet, mRange, etc. These are usually in my Personal workbook for easy access.
    Last edited by Kenneth Hobson; 08-23-2013 at 12:14 PM.

  3. #3
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Getting error user define type not define

    Hello Kenneth Hobson,
    Thank you for your guidance. I will follow your suggestions positively in my workbook in future.

    After opening the file I want to open outlook first and then anniversary macro to send the mail automatically. Here I'm getting error. The error is in anniversary macro. Please suggest me a solution to remove it. I'm using outlook 2007 and outlook object version is 12. I want to minimise the outlook after opening it automatically.

    Solution please!

    Mukesh

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Getting error user define type not define

    Please be more specific about the Error. Stepping through the code with F8, you can find where it may error.

    Had you used the Option Explicit, and then used Compile, you would have seen that you were missing the Dim for the Outlook Application. I recommend editing your VBA toolbar and add Compile.

    I fixed the Dim issue and added code that may minimize the window. I don't use Outlook on this computer so I can not test.

    Sub Anniversary()
      Dim OutlookApp As Outlook.Application
      Dim tRow As Integer
      Dim Name As String
      Dim t As Variant
      Dim MItem As Outlook.MailItem
      Dim cell As Range
      Dim Subj As String
      Dim EmailAddr As String
      Dim Recipient As String
      Dim Msg1 As String, Msg2 As String, Msg3 As String, Msg4 As String
      Dim Msg5 As String, Msg6 As String, Msg7 As String, Msg8 As String
      Dim Msg9 As String, Msg10 As String, Msg11 As String, Msg12 As String
          
      Application.ScreenUpdating = False
      
      Range("t7").Interior.Color = xlNone
      Do
          ActiveCell.Offset(1, 0).Select
          tRow = ActiveCell.Row
          If Range("t" & tRow).Value = "-" Then GoTo lblLoop
          On Error GoTo lblLoop
          If Month(Range("t" & tRow).Value) = Month(Now()) And Day(Range("t" & tRow).Value) = Day(Now()) Then
          On Error GoTo 0
          ActiveCell.Offset(0, -1).Interior.ColorIndex = 6
          Name = ActiveCell.Offset(0, -1).Value
          MsgBox (Name & "'s Birthday Today!"), vbOKOnly
       '-------------------  Start Creating Email using outlook ---------------
      'Create Outlook object
          Set OutlookApp = New Outlook.Application
          ' http://answers.microsoft.com/en-us/office/forum/office_2007-customize/minimizing-the-outlook-window-with-vba/7e05e400-21f3-4d32-962d-3941a82c583c
          OutlookApp.ActiveWindow.WindowState = 1
          EmailAddr = ActiveCell.Offset(0, 6).Value
          Msg1 = "Dear " & Name & ","
          Msg2 = """Hope your Special day"
          Msg3 = "Brings you all that"
          Msg4 = "Your heart desires"
          Msg5 = "Here's wishing you a day"
          Msg6 = "Full of pleasant surprises!"
          Msg7 = "Happy Birthday"""
          Msg8 = "I have a great pleasure to convey my best wishes on the occasion of your Birth Day!"
          Msg9 = """May God offer you a very Healthy and Wealthy life ahead!!"""
          Msg10 = "Please see the attachment."
          Msg11 = "With regards,"
          Msg12 = "Mukesh Baviskar"
          Subj = "Happy Birthday"
          
          'Create Mail Item and view before sending
          Set MItem = OutlookApp.CreateItem(olMailItem)
          With MItem
              .To = EmailAddr
              .Subject = Subj
              '.HTMLBody = "<center><img src='C:\Cake.jpg'></center><br><br>" 'Insert the full windows path of your image here
      '        .HTMLBody = .HTMLBody & "<font color='red'>"
              .HTMLBody = "<html>" & "<center><img src='C:\Cake.jpg'></center><br><br>" & "<br/>" & "<font face=""Arial"" size=""2"" color=""FF1CAE"">" & _
              Msg1 & "<center><b><font face=""Arial"" size=""2"" color=""blue"">" & "<br/>" & "<br/>" & _
              Msg2 & "<br>" & Msg3 & "<br>" & Msg4 & "<br>" & Msg5 & "<br>" & Msg6 & "<br>" & Msg7 & "</font></b></center>" _
               & "<br><br><font color='FF1CAE'>" & Msg8 & "<br><br>" & Msg9 & "<br><br>" & _
                  Msg10 & "<br><br>" & "<font face=""Arial"" size=""2"" color=""red"">" & Msg11 & "<br><br>" & Msg12 & "</font>"
                      '.Attachments.Add ("c://Happy Birthday.xlsm")  ' for example
              .Display
              .Send
          End With
      
          Set OutApp = Nothing
          Set OutMail = Nothing
      
           '-------------------  End Creating Email using outlook ---------------
          End If
    lblLoop:
      Loop Until IsEmpty(ActiveCell.Offset(1, 0)) = True
      
      Application.ScreenUpdating = True
    End Sub
    Last edited by Kenneth Hobson; 08-23-2013 at 12:56 PM.

  5. #5
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Getting error user define type not define

    I made changes suggested by you but still the problem is not solved. The error is in this line.

    Dim OutlookApp As Outlook.Application

    Please suggest me how to remove this error.

    Thanking you in anticipation.

    Mukesh
    Last edited by mukeshbaviskar; 08-26-2013 at 10:36 PM.

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Getting error user define type not define

    If you are going to use early binding like that, you must set the Outlook object reference.

    For your problem, in the Visual Basic Editor (VBE), select Tools > References > Microsoft Outlook 14.0 Object Library > OK. Obviously, the 14.0 should be changed if not Outlook 2010.

  7. #7
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Getting error user define type not define

    Dear Kenneth Hobson,
    Good morning! I have already mentioned in my previous reply that I'm using outlook 2007 and set outlook object library 12 in vbe. But still the problem is occurring. So I humbly request you to look in this problem positively.

    Is there anything wrong in my code? I mentioned in which line I'm getting error in anniversary macro. Please refer my previous reply again for avoide confusion.

    Thanking you in anticipation.

    Mukesh

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Getting error user define type not define

    If you had set the reference, then I should have seen a broken reference in your example.

    I guess you can try late binding if you can not make the early binding method work. This MVP has an example or two. http://www.erlandsendata.no/english/...controloutlook

    You might want to look into CDO.
    'If locked out of CDO, install: http://www.dimastr.com/redemption/
    'http://www.vbaexpress.com/forum/showthread.php?t=22439

    http://www.outlook-stuff.com/lang-en...anhaengen.html

    Here is a late binding method:
    'xld, http://vbaexpress.com/forum/showthread.php?t=21633
    Private OLApp As Object
    Private OLNS As Object
     
    Public Sub ProcessData()
        Dim i As Long
        Dim LastRow As Long
         
        With ActiveSheet
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
            Set OLApp = CreateObject("Outlook.Application")
            Set OLNS = OLApp.GetNameSpace("MAPI")
            OLNS.Logon , , True
            For i = 2 To LastRow
                MailIt .Cells(i, "C").Value, .Cells(i, "A").Value, .Cells(i, "B").Value
            Next i
        End With
    End Sub
     
    Private Sub MailIt(eMail As String, pName As String, pCompany As String)
        Dim oMailItem As Object
        Dim oRecipient As Object
         
        Set oMailItem = OLApp.CreateItem(0)
        Set oRecipient = _
        oMailItem.Recipients.Add(eMail)
        oRecipient.Type = 1
        With oMailItem
            .Subject = "Here is my subject"
            .Body = "To: " & pName & vbNewLine & _
            "of: " & pCompany & vbNewLine & vbNewLine & _
            "This is an automatic email notification."
            .Send 'use .Display to test
        End With
    End Sub

  9. #9
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Getting error user define type not define

    Dear Kenneth Hobson,
    Thank you for guidance but I'm totally confused due to my little knowledge of vba. Therefore I request to modify my code and send a copy to me to avoide problem again.

    Please do it for me to solve my problem positively. Sorry for trouble.

    Thanking you in anticipation.

    Mukesh

  10. #10
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Getting error user define type not define

    Dear Kenneth Hobson,
    Thank you for your cooperation and sincere efforts to solve my problem. I think to leave off the idea of sending mail through outlook because it's giving problem to me repeatedly.

    To avoide it I have decided to accept the idea to send mail using CDO. I tried my level best to create a code but it's giving error. Please go through it and solve my problem to complete my program.

    I want to send the mails to the different recipients on their birthday but I'm not able to do it in code. Look into this problem please. The date should be in the center align which is now left align.

    Thanking you in anticipation.

    Mukesh
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] user define function (max if)
    By ck_123 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-11-2013, 12:28 PM
  2. error 1004 application define or object define
    By jay11 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-11-2011, 04:09 AM
  3. Define named range where user can define size
    By nahousto in forum Excel General
    Replies: 4
    Last Post: 07-06-2009, 05:09 PM
  4. Define 'tails' and 'type' better than the TTEST help file.
    By goodmonkey in forum Excel General
    Replies: 1
    Last Post: 05-04-2005, 11:06 PM
  5. Array of User define data.
    By Cactus [ÏÉÈËÇ&ograv in forum Excel General
    Replies: 5
    Last Post: 01-22-2005, 11:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1