2
我是Outlook VBA的新手,我試圖比較來自兩個不同封閉工作簿的同一單元格中的值。Outlook Excel比較來自兩個封閉工作簿的數據
我從一封將附件保存爲CSV文件的電子郵件收到附件後創建了一個Excel對象。
然後我想檢查文件中的標題行是否與第一行中具有相同標題的主副本匹配,但我不確定如何引用表單名稱或使用對象的單元格。 我已經嘗試了很多使用VBA for Excel的方法,但它似乎並不適用於Outlook。
如果有人能幫助我,將不勝感激。
Function ConvertXls2CSV(sXlsFile As String)
On Error Resume Next
Dim oExcel As Object
Dim oExcelWrkBk As Object
Dim bExcelOpened As Boolean 'Was Excel already open or not
Dim OriginalFile As String
Dim MasterFile As String
Dim Fault As Integer
Set oExcel = GetObject(, "Excel.Application") 'Bind to existing instance of Excel
If Err.Number <> 0 Then 'Could not get instance of Excel, so create a new one
Err.Clear
On Error GoTo Error_Handler
Set oExcel = CreateObject("excel.application")
bExcelOpened = False
Else 'Excel was already running
bExcelOpened = True
End If
Set oExcelWrkBk = oExcel.Workbooks.Open(sXlsFile)
oExcelWrkBk.SaveAs Left(sXlsFile, InStrRev(sXlsFile, ".")) & "csv", xlCSVWindows
/*THIS IS WHERE I WANT TO REFERENCE THE CELLS IN THE WORKBOOKS*/
OriginalFile = oExcelWrkBk.Sheets("PK Price Data").Cells(1, 1).Value
MasterFile = oExcelWrkBk."MasterFile.xls".Sheets("PK Price Data").Cells(1, 1).Value
if OriginalFile = MasterFile then
fault = 1
else fault = 0
end if
oExcelWrkBk.Close False
If bExcelOpened = False Then
oExcel.Quit
End If
End Function
非常感謝 梅琳達
爲什麼你要做的是Outlook?如果您正在處理Excel工作簿,Excel VBA會更加明智。你不知道如何循環工作表,行和單元格嗎? –