我正在创建一个宏,以将嵌入在Outlook电子邮件中的HTML表导出到Excel。
导出片很好,但是保存时遇到了麻烦。我想将新文件保存在特定的文件夹中,并且名称应为电子邮件的主题。
我在x FilePath =“ \ xxx \ docs \ Testing \”和strSubject 部分遇到问题。
如果我使用特定的文件名(例如“ \ xxx \ docs \ Testing \ test.csv”),则使用该名称保存文件,没有任何问题。但是,如果我尝试使用电子邮件的主题使其动态化,则不会保存文件。有什么想法吗?
在整个代码下面:
代码:
Sub ImportTableToExcel()
Dim xMailItem As MailItem
Dim xTable As Word.Table
Dim xDoc As Word.Document
Dim xExcel As Excel.Application
Dim xWb As Workbook
Dim xWs As Worksheet
Dim I As Integer
Dim xRow As Integer
Dim xFilePath As String
Dim strSubject As String
On Error Resume Next
Set xExcel = New Excel.Application
Set xWb = xExcel.Workbooks.Add
xExcel.Visible = True
Set xWs = xWb.Sheets(1)
xRow = 1
For Each xMailItem In Application.ActiveExplorer.Selection
Set xDoc = xMailItem.GetInspector.WordEditor
For I = 1 To xDoc.Tables.count
Set xTable = xDoc.Tables(I)
xTable.Range.Copy
xWs.Paste
xRow = xRow + xTable.Rows.count + 1
xWs.Range("A" & CStr(xRow)).Select
Next
Next
strSubject = xMailItem.Subject
xFilePath = "\\xxx\docs\Testing\" & strSubject
xWs.SaveAs xFilePath
xWs.Close
End Sub