从 Outlook VBA 搜索 Excel 工作表
Searching an Excel Worksheet from Outlook VBA
我有一个可以打开一些 excel 文件的 Outlook 宏。我想知道如何在我的 Outlook 宏中使用 Cells.find 语法和 workbooks.Activate 语法。
'OUTLOOK VBA CODE here (works fine)...
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
With xlApp
.Visible = True
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
.Workbooks.Open ("J:\Retail Finance\Varicent\General Resources\Acting Mgr Assignment Bonus Aggregation.xlsx")
For Each x In AttachNames
'Open the Attachments (one by one as loop iterates)
.Workbooks.Open ("J:\Retail Finance\Varicent\General Resources\AAA\" & AttachNames(i))
'Find the Word End, Activate the Cell that it resides in
'####This syntax doesn't work ####
.Worksheets.Cells.Find(What:="End", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
'Declare that row the "Endrow"
'####I'm betting this won't work either####
endrow = ActiveCell.Row
'Copy the range of Acting & Additional Bonuses in the file
xlApp.Worksheet.Rows("6:" & endrow - 1).Copy
'Activate the Aggregation File,
'####Code for activating a particular workbook####
'find end,
'Cells.Find(What:="End", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
你的 With
块正在使用 xlApp
而你错误的行开始于 .Worksheets
xlApp
没有 .Worksheets
集合,因此无法使用。您需要先参考工作簿。
最后,.Worksheets
是一个集合 - 您需要指定您实际想要定位的索引 (sheet):
Dim wb As Object
Set wb = .Workbooks.Open ("J:\Retail Finance\Varicent\General Resources\AAA\" & AttachNames(i))
wb.Worksheets(1).Find("something") '// etc etc....
我有一个可以打开一些 excel 文件的 Outlook 宏。我想知道如何在我的 Outlook 宏中使用 Cells.find 语法和 workbooks.Activate 语法。
'OUTLOOK VBA CODE here (works fine)...
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
With xlApp
.Visible = True
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
.Workbooks.Open ("J:\Retail Finance\Varicent\General Resources\Acting Mgr Assignment Bonus Aggregation.xlsx")
For Each x In AttachNames
'Open the Attachments (one by one as loop iterates)
.Workbooks.Open ("J:\Retail Finance\Varicent\General Resources\AAA\" & AttachNames(i))
'Find the Word End, Activate the Cell that it resides in
'####This syntax doesn't work ####
.Worksheets.Cells.Find(What:="End", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
'Declare that row the "Endrow"
'####I'm betting this won't work either####
endrow = ActiveCell.Row
'Copy the range of Acting & Additional Bonuses in the file
xlApp.Worksheet.Rows("6:" & endrow - 1).Copy
'Activate the Aggregation File,
'####Code for activating a particular workbook####
'find end,
'Cells.Find(What:="End", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
你的 With
块正在使用 xlApp
而你错误的行开始于 .Worksheets
xlApp
没有 .Worksheets
集合,因此无法使用。您需要先参考工作簿。
最后,.Worksheets
是一个集合 - 您需要指定您实际想要定位的索引 (sheet):
Dim wb As Object
Set wb = .Workbooks.Open ("J:\Retail Finance\Varicent\General Resources\AAA\" & AttachNames(i))
wb.Worksheets(1).Find("something") '// etc etc....