Как отфильтровать столбец в определенном файле Excel на основе выбранной фразы / слова или числа в электронном письме Outlook? - PullRequest
0 голосов
/ 14 января 2019

Я пишу код для фильтрации листа Excel по выбранной строке из электронной почты Outlook. Мне нужна помощь, чтобы завершить это. В настоящее время выдает ошибку 'sub или function notfined' в Range("A1").Select

Sub Search_AccountNumber()

Dim OutApp As Object
Dim OutMail As Object
Dim olInsp As Object
Dim wdDoc As Object
Dim strText As String
Dim xlApp As Object
Dim xlWB As Object
Dim xlSheet As Object
Dim strPath As String

On Error Resume Next
'Get Outlook if it's running
Set OutApp = GetObject(, "Outlook.Application")

'Outlook wasn't running, so cancel
If Err <> 0 Then
    MsgBox "Outlook is not running so nothing can be selected!"
    GoTo lbl_Exit
End If
On Error GoTo 0

Set OutMail = OutApp.ActiveExplorer.Selection.Item(1)
With OutMail
    Set olInsp = .GetInspector
    Set wdDoc = olInsp.WordEditor
    strText = wdDoc.Application.Selection.Range.Text
End With

Debug.Print strText

strPath = "C:\Users\pvishwas\Documents\WORK\Agings\2019\January'19.xlsx"
 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("Aging")

 xlSheet.Activate

With xlSheet
 Range("A1").Select
 Selection.AutoFilter
 Range("F1").Select
 xlSheet.Range("$A$1:$AZ$10000").AutoFilter Field:=6, Criteria1:=strText
End With

lbl_Exit:
   Set OutMail = Nothing
   Set OutApp = Nothing
   Set olInsp = Nothing
   Set wdDoc = Nothing
Exit Sub
End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...