outlook中利用vba操作excel的内容问题
Subss(ItemAsOutlook.MailItem)'OnErrorResumeNextDimxAsIntegerIfItem.Attachments.Count>...
Sub ss(Item As Outlook.MailItem)
'On Error Resume Next
Dim x As Integer
If Item.Attachments.Count > 0 Then
For x = 1 To Item.Attachments.Count
'MsgBox Item.Attachments(x).FileName
Item.Attachments(x).SaveAsFile ("d:\" & Item.Attachments(x).FileName)
Dim exlApp As Excel.Application
Dim workbook As Excel.workbook
Set exlApp = CreateObject("Excel.Application")
Set workbook1 = exlApp.Workbooks.Open("d:\" & Item.Attachments(x).FileName) '从收件箱附件中提取的表格
Set workbook2 = exlApp.Workbooks.Open("d:\222.xlsx") '本地已存在的表格
myrange1 = workbook1.sheets("sheet2").UsedRange
hangs1 = UBound(myrange1, 1) '获取行数
lies1 = UBound(myrange1, 2) '获取列数
MsgBox hangs1 & lies1 '测试用,显示workbook1中已用单元格的行数和列数
'以上代码均可成功运行,唯独以下一行代码不能成功运行,什么原因?
workbook1.sheets(sheet2).range("a1").Copy workbook2.sheets(1).cells(1, 1) '将workbook1中某个工作表的单元格内容复制到workbook2的某个工作表中
Next
End If
End Sub 展开
'On Error Resume Next
Dim x As Integer
If Item.Attachments.Count > 0 Then
For x = 1 To Item.Attachments.Count
'MsgBox Item.Attachments(x).FileName
Item.Attachments(x).SaveAsFile ("d:\" & Item.Attachments(x).FileName)
Dim exlApp As Excel.Application
Dim workbook As Excel.workbook
Set exlApp = CreateObject("Excel.Application")
Set workbook1 = exlApp.Workbooks.Open("d:\" & Item.Attachments(x).FileName) '从收件箱附件中提取的表格
Set workbook2 = exlApp.Workbooks.Open("d:\222.xlsx") '本地已存在的表格
myrange1 = workbook1.sheets("sheet2").UsedRange
hangs1 = UBound(myrange1, 1) '获取行数
lies1 = UBound(myrange1, 2) '获取列数
MsgBox hangs1 & lies1 '测试用,显示workbook1中已用单元格的行数和列数
'以上代码均可成功运行,唯独以下一行代码不能成功运行,什么原因?
workbook1.sheets(sheet2).range("a1").Copy workbook2.sheets(1).cells(1, 1) '将workbook1中某个工作表的单元格内容复制到workbook2的某个工作表中
Next
End If
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询