2016-04-13 68 views
-1

我正在使用VBA腳本剝離電子郵件正文,我已成功剝離了90%的電子郵件,但是當我到達最終「查詢」部分時,我有錯誤我無法修復。這是電子郵件正文。剝離電子郵件正文時出現VBA展望錯誤

Ref: 1993 
Business Headline: bla bka 
Name: A Name 
Email: [email protected] 
Tel: 0777777777 

Address Line: 123 
Address Line 2: someroad 
Town: sometown 
County: lancashire 
Postcode: APOS TCDE 

Enquiry: 
Please send me more information about this business. Regards, Gary. 

問題是在郵政編碼時,它試圖找到查詢。在我的代碼中,似乎找到了查詢的位置,但並未將該整數賦值給該變量。請看截圖,看看我的意思。

finds correct positon

The variable is just staying at 0

這是郵編剝離代碼:

Dim pstcodee As Integer 
      pstcodee = InStr(1, b4, "Postcode: ") 

     Dim enqui As Integer 
      enqui = InStr(1, b4, "Enquiry:") 

     Dim pstenquire As String 
      pstenquire = Mid(b4, pstcodee, enqui - pstcodee) 

     Dim bup2222() As String 
     bup2222 = Split(pstenquire, ":") 

     postcode = bup2222(1) 
+0

代碼工作正常,並提取:_ 「APOS TCDE」 _。你必須更詳細地描述確切的問題是什麼。屏幕截圖不顯示當前執行的行是什麼(在調試過程中用黃色標記)。 – BrakNicku

回答

0
postcode = Trim$(Mid$(b4, 8 + Len("Enquiry:" & vbNewLine), Len(b4)))