Variable not defined x1up excel 2003 VBA

soccerjon1013

New Member
Joined
Apr 16, 2012
Messages
48
I get e-mails through out the day that are subject "AUP Suspension of account : email@domain.com/net" and am trying to have it take the e-mail address from the body, and paste it on the bottom like of my excel document and getting this error. I would love any idea on how to fix it and if it's possible to get it to capture the date it was received also.


Code:
Option Explicit
 Sub AUPCopyToExcel(olItem As Outlook.MailItem)
 Dim xlApp As Object
 Dim xlWB As Object
 Dim xlSheet As Object
 Dim vText, vText2, vText3, vText4, vText5 As Variant
 Dim sText As String
 Dim rCount As Long
 Dim bXStarted As Boolean
 Dim enviro As String
 Dim strPath As String
 Dim Reg1 As Object
 Dim M1 As Object
 Dim M As Object
               
enviro = CStr(Environ("USERPROFILE"))
'the path of the workbook
 strPath = enviro & "\\shedevil\tss\tierii\suspended email\aup contact list\2015\2015.xls"
     On Error Resume Next
     Set xlApp = GetObject(, "Excel.Application")
     If Err <> 0 Then
         Application.StatusBar = "Please wait while Excel source is opened ... "
         Set xlApp = CreateObject("Excel.Application")
         bXStarted = True
     End If
     On Error GoTo 0
     'Open the workbook to input the data
     Set xlWB = xlApp.Workbooks.Open(strPath)
     Set xlSheet = xlWB.Sheets("Test")
 
    'Find the next empty line of the worksheet
     rCount = xlSheet.Range("B" & xlSheet.Rows.Count).End(xlUp).Row
     rCount = rCount + 1
      
     sText = olItem.Body
 
     Set Reg1 = CreateObject("VBScript.RegExp")
    ' \s* = invisible spaces
    ' \d* = match digits
    ' \w* = match alphanumeric
      
    With Reg1
        .Pattern = "ˆ([\w-]+\.)*[\w-]+@([\w-]+\.)+[a-z]{2,4}$"
    End With
    If Reg1.test(sText) Then
      
' each "(\w*)" and the "(\d)" are assigned a vText variable
        Set M1 = Reg1.Execute(sText)
        For Each M In M1
           vText = Trim(M.SubMatches(1))
        Next
    End If
 
  xlSheet.Range("B" & rCount) = vText


 
     xlWB.Close 1
     If bXStarted Then
         xlApp.Quit
     End If
     Set M = Nothing
     Set M1 = Nothing
     Set Reg1 = Nothing
     Set xlApp = Nothing
     Set xlWB = Nothing
     Set xlSheet = Nothing
 End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
The constant name is xlup, not x1up.

What line fails, with what message?
 
Upvote 0
I'm sorry, your right.

'Find the next empty line of the worksheet
rCount = xlSheet.Range("B" & xlSheet.Rows.Count).End(xlUp).Row
rCount = rCount + 1

it highlights the text in blue, and gives Compile Error: Variable not defined.
 
Upvote 0
Ah-- you're automating this from Outlook. You need to declare the constants:

Code:
  Const xlUp As Long = -4162
 
Upvote 0
That absolutely fixed that problem, thank you so much.

However I get a message requesting to a program wants to access my contacts, and ask me to allow it. I hit yes, I see the file has been modified at the current time, however it does not paste the information. Do you know what I'm doing wrong here? The e-mail addresses can be *@*.com as well as *@*.net My body of the e-mail looks like this:





Hello,<o:p></o:p></pre>
</pre>
The following account has been suspended due to complaints received by<o:p></o:p></pre>
recipients regarding the content of the messages having abusive spam<o:p></o:p></pre>
behaviour and/or massmailing patterns within the OpenSRS Hosted Environment.<o:p></o:p></pre>
</pre>
This is due to repeat complaints from recipients and/or high volume outbound<o:p></o:p></pre>
spam.<o:p></o:p></pre>
</pre>
We have taken the following action:<o:p></o:p></pre>
* Placed this end user under AUP Violation<o:p></o:p></pre>
* Placed this end user on our internal abuse list<o:p></o:p></pre>
</pre>
Please take the following actions:<o:p></o:p></pre>
* Inform the account owner of the reasons for suspension (provide evidence<o:p></o:p></pre>
as needed)<o:p></o:p></pre>
* Take appropriate action to ensure this activity does not continue.<o:p></o:p></pre>
* Remove the AUP Violation flag or permanently disable the account<o:p></o:p></pre>
</pre>
The account in question is:<o:p></o:p></pre>
</pre>
*@*.com<o:p></o:p></pre>
</pre>
IMPORTANT: If you determine that this account name is NOT related to repeat<o:p></o:p></pre>
spammers, and is legitimate, please let us know ASAP, or as new accounts are<o:p></o:p></pre>
created that have a similar pattern, they may also be suspended.<o:p></o:p></pre>
</pre>
Thanks,<o:p></o:p></pre>
</pre>
OpenSRS Abuse Administrator<o:p></o:p></pre>
 
Upvote 0

Forum statistics

Threads
1,216,153
Messages
6,129,179
Members
449,491
Latest member
maxim_sivakon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top