【问题标题】:Exported CSV won't import into Outlook until it's re-saved in Excel导出的 CSV 在重新保存在 Excel 中之前不会导入 Outlook
【发布时间】:2016-12-01 14:12:07
【问题描述】:

我有一个从 Access 导出到 CSV 文件的过程,以便可以将其导入 Outlook。

但是,一旦我尝试将其导入 Outlook,它就会失败,并说存在 MAPI 错误 0x80040107。

在 Excel 中打开 CSV 文件后,我按“保存”并保存它 - 它提示我保存 CSV,所以我按“是”。然后我关闭了它,但在关闭之前,它再次要求我将其保存为 CSV,所以我做了 - 这次出现了保存对话框,所以我输入了相同的文件名和扩展名(客户 A-F.csv),因为该文件已经存在,它要求我替换它或取消它。当我按“是”替换现有文件时,Excel 文件关闭。

我现在尝试将同一文件的新版本导入 Outlook - 但这次成功了!

以前有人遇到过这个问题吗?我真的不明白为什么打开文件然后将其保存为相同的名称/类型可以解决问题?

如果有帮助,这是我的代码;

If MsgBox("Are you sure you wish to output this customer data to Outlook?", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then

  Dim sPath As String = ""

  Using ofd As New SaveFileDialog
      ofd.Filter = "CSV files (*.csv)|*.csv"
      ofd.FilterIndex = 1
      ofd.FileName = "Customers " & range
        If ofd.ShowDialog = DialogResult.OK Then
            sPath = ofd.FileName & ""
        End If
  End Using

    ExportToCSV(dgvExport.DataSource, sPath)

    Me.Cursor = Cursors.Default
    MsgBox("Export Successful!", MsgBoxStyle.OkOnly, "CSV Exported Successfully")

End If

导出到CSV

 Dim result As Boolean = True

    Try
        Dim sb As New StringBuilder()
        Dim separator As String = ","
        Dim group As String = """"
        Dim newLine As String = Environment.NewLine

        For Each column As DataColumn In dtable.Columns
            sb.Append(wrapValue(column.ColumnName, group, separator) & separator)
        Next

        sb.Append(newLine)

        For Each row As DataRow In dtable.Rows
            For Each col As DataColumn In dtable.Columns
                sb.Append(wrapValue(row(col).ToString(), group, separator) & separator)
            Next

            sb.Append(newLine)
        Next

        Using fs As New StreamWriter(fileName)
            fs.Write(sb.ToString())
        End Using


    Catch ex As Exception
        Console.WriteLine(ex.Message & vbCrLf & ex.StackTrace)
        result = False

    End Try

    Return result

包装值

Function wrapValue(value As String, group As String, separator As String) As String

    If value.Contains(group) Then
        value = value.Replace(group, group + group)
    End If

    value = group & value & group

    Return value

End Function

【问题讨论】:

  • 抱歉,您想使用 VBA 将某些内容从 Access 导出到 Outlook 吗?我相信您可以做到这一点,但是您究竟在导出和导入什么?您似乎更有可能从 Outlook 转到 Access。请提供更多背景信息来准确描述您正在尝试做的事情。谢谢。

标签: excel vb.net csv outlook


【解决方案1】:

这个问题已经得到了回答,但在另一个问题中。

如果这是其他人的问题,问题已解决here

这与需要重新保存无关,这与 OP 添加 "" 的事实有关,而实际上,它们不需要/不应该是。

【讨论】:

    猜你喜欢
    • 2011-07-31
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 2011-10-01
    相关资源
    最近更新 更多