VBA find/replace 代码 .Execute Replace:=wdReplaceAll 不工作
VBA find/replace code .Execute Replace:=wdReplaceAll is not working
我正在努力将 Outlook 电子邮件可用日期导出到 excel sheet。但是遇到了.Execute Replace:=wdReplaceAll
错误。我已启用必要的
尝试在编辑前取消保护邮件
(回答 )
...
Set oLookWordDoc = oLookInspector.WordEditor
oLookWordDoc.UnProtect
...
问题已通过以下代码解决
Set xExcelApp = CreateObject("Excel.Application")
Set xWb = xExcelApp.Workbooks.Open(mypath)
xExcelApp.Visible = True
Set xWs = xWb.Sheets("Sheet1")
xWs.Activate
Set oLookwordTbl = oLookWordDoc.Tables(1) 'Grab the word table
colcount = oLookwordTbl.Columns.Count
For iRow = 2 To oLookwordTbl.Rows.Count
'oLookwordTbl.Rows(iRow).Range.Copy
For icol = 1 To colcount
cellvalue = oLookwordTbl.Cell(iRow, icol)
cellvalue = Replace(cellvalue, Chr(13), "")
cellvalue = Replace(cellvalue, Chr(10), "")
cellvalue = Replace(cellvalue, Chr(244), "")
cellvalue = Replace(cellvalue, "^p", "")
cellvalue = Left(cellvalue, Len(cellvalue) - 1)
xWs.Cells(iRow, icol).Value = cellvalue
Next
Next
xWs.Cells(xWs.Rows.Count, 1).End(3).Offset(1).Select
End Sub
我正在努力将 Outlook 电子邮件可用日期导出到 excel sheet。但是遇到了.Execute Replace:=wdReplaceAll
错误。我已启用必要的
尝试在编辑前取消保护邮件 (回答 )
...
Set oLookWordDoc = oLookInspector.WordEditor
oLookWordDoc.UnProtect
...
问题已通过以下代码解决
Set xExcelApp = CreateObject("Excel.Application")
Set xWb = xExcelApp.Workbooks.Open(mypath)
xExcelApp.Visible = True
Set xWs = xWb.Sheets("Sheet1")
xWs.Activate
Set oLookwordTbl = oLookWordDoc.Tables(1) 'Grab the word table
colcount = oLookwordTbl.Columns.Count
For iRow = 2 To oLookwordTbl.Rows.Count
'oLookwordTbl.Rows(iRow).Range.Copy
For icol = 1 To colcount
cellvalue = oLookwordTbl.Cell(iRow, icol)
cellvalue = Replace(cellvalue, Chr(13), "")
cellvalue = Replace(cellvalue, Chr(10), "")
cellvalue = Replace(cellvalue, Chr(244), "")
cellvalue = Replace(cellvalue, "^p", "")
cellvalue = Left(cellvalue, Len(cellvalue) - 1)
xWs.Cells(iRow, icol).Value = cellvalue
Next
Next
xWs.Cells(xWs.Rows.Count, 1).End(3).Offset(1).Select
End Sub