+ Reply to Thread
Results 1 to 9 of 9

Compile error variable not defined

Hybrid View

AsifShabbir Compile error variable not... 03-31-2011, 07:43 AM
6StringJazzer Re: Complie error variable... 03-31-2011, 09:26 AM
AsifShabbir Re: Complie error variable... 04-01-2011, 05:59 AM
jwright650 Re: Complie error variable... 04-01-2011, 07:43 AM
AsifShabbir Re: Complie error variable... 04-01-2011, 07:55 AM
AsifShabbir Re: Complie error variable... 04-01-2011, 08:02 AM
jwright650 Re: Complie error variable... 04-01-2011, 08:06 AM
AsifShabbir Re: Complie error variable... 04-04-2011, 04:58 AM
jwright650 Re: Complie error variable... 04-04-2011, 10:53 AM
  1. #1
    Registered User
    Join Date
    03-02-2011
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    34

    Compile error variable not defined

    Hi,

    I am using macro of Ron for auto mail generation and I have modified it according to my need but as for as I use the original sheet of Ron and make changes on it, it works but when I copy this code into new sheet it gives error message Compile Error: variable not defined. Please help me solving this.

    I am attaching the sheet in which I am using this code. In this sheet I want excel to generate mail when 42 days left in review date.

    2nd thing I want excel to do is generating a reminder mail when 10 days left in review date and show in Reminder column whether reminder sent or not.

    Waiting help for you experts.

    Asif
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,816

    Re: Complie error variable not defined

    FormulaCell is undeclared. Add a declaration for it

    Dim FormulaCell As Range
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    03-02-2011
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Complie error variable not defined

    Hi 6StringJazzer,

    No it doesn;t work as now it gives message (Runtime Error 91: Object variable or with block variable not set). Further in the original worksheet of Ron, he hasn;t added this line as I have changed only Formula range and in mail code ( in my case module 1) the body of the mail.

    Thanks

  4. #4
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Complie error variable not defined

    I declared a variable for FormulaCell, and used it as the LastRow

    Try this:
    Option Explicit
    
    Sub Mail_with_outlook1()
    'For mail code examples visit my mail page at:
    'http://www.rondebruin.nl/sendmail.htm
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strto As String, strcc As String, strbcc As String
        Dim strsub As String, strbody As String
        Dim FormulaCell As Object
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        Set FormulaCell = Sheet1.Range("a65536").End(xlUp)
    
        strto = Cells(FormulaCell.Row, "K").Value
        strcc = ""
        strbcc = ""
        strsub = "Review Date Due"
        strbody = "Hi there" & vbNewLine & vbNewLine & _
                  "Review date of " & Cells(FormulaCell.Row, "A").Value & _
                  " titled  " & Cells(FormulaCell.Row, "B").Value & _
                  "  located at:" & vbNewLine & vbNewLine & Cells(FormulaCell.Row, "L").Value & vbNewLine & vbNewLine & _
                   " is due on " & Cells(FormulaCell.Row, "D").Value & "." & _
                  vbNewLine & vbNewLine & "Please take appropriate action." & _
                  vbNewLine & vbNewLine & "Best Regards," & _
                  vbNewLine & vbNewLine & "Asif Shabbir"
    
    
    
    
        With OutMail
            .To = strto
            .CC = strcc
            .BCC = strbcc
            .Subject = strsub
            .Body = strbody
            'You can add a file to the mail like this
            '.Attachments.Add ("C:\test.txt")
            .Display    ' or use .Send
        End With
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    Last edited by jwright650; 04-01-2011 at 07:44 AM. Reason: added comment
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

  5. #5
    Registered User
    Join Date
    03-02-2011
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Complie error variable not defined

    No its not working. Have you tried it? may be I am doing some mistake. another confusion in my mind is that I have copied all the codes from Ron's sheet but its working on his sheet but not on mine. what is the logic?

    Thanks

  6. #6
    Registered User
    Join Date
    03-02-2011
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Complie error variable not defined

    By the way it is now giving original message i.e compile error: variable not defined. Sorry to add one more thing that I want excel to initiate mailing process ( for reminder) in the way like Ron did i.e. Sen or Not sent message in nex column (Column G) and I want Reminder sent or Not sent in Column H.
    I hope, I am not bothering you

  7. #7
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Complie error variable not defined

    I added my email addy to Column K and it filled in the email...all I had to do was hit "send" and it sent me an email from outlook.

    You may want to write a macro to call this code when a condition is satisfied and then it would send the email for you out of Excel.

  8. #8
    Registered User
    Join Date
    03-02-2011
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Complie error variable not defined

    That's what I am trying to do but unsuccessful.

  9. #9
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Complie error variable not defined

    Asif,
    Thought about this thread when I saw this....
    See if you can glean any useful info from this.
    Click Here

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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