【问题标题】:VBA table into outlook, loses proper formatVBA表进入Outlook,失去正确的格式
【发布时间】:2015-05-25 18:29:49
【问题描述】:

我正在使用 Ron De Bruin 的代码将表格嵌入到 Outlook (http://www.rondebruin.nl/win/s1/outlook/bmail2.htm) 的电子邮件中。但是,当它进入电子邮件时,我的数字之间的空格然后边框消失了,数字基本上是在触摸它。我怎样才能让这个空间留下来/回来?

编辑:HTML 代码部分如下

Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
 .Cells(1).PasteSpecial Paste:=8
    .Cells(1).PasteSpecial xlPasteValues, , False, False
    .Cells(1).PasteSpecial xlPasteFormats, , False, False
    .Cells(1).Select
    Application.CutCopyMode = False
    On Error Resume Next
    .DrawingObjects.Visible = True
    .DrawingObjects.Delete
    On Error GoTo 0
End With




With TempWB.PublishObjects.Add( _
     SourceType:=xlSourceRange, _
     FileName:=TempFile, _
     sheet:=TempWB.Sheets(1).Name, _
     Source:=TempWB.Sheets(1).UsedRange.Address, _
     HtmlType:=xlHtmlStatic)
    .Publish (True)
End With


Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                      "align=left x:publishsource=")

TempWB.Close Savechanges:=False

Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing

End Function

【问题讨论】:

  • HTML 标记的结果是什么?
  • 您能否添加电子邮件正文的图像以查看问题的样子
  • @EugeneAstafiev 我已编辑问题以包含代码的 HTML 部分。感谢您的帮助!
  • @Omar 我也刚刚附上了照片。谢谢!
  • 尝试这样做Cells(1).Select '<<---- ChangeCells(1).EntireRow.AutoFit '<<-- AddCells(1).EntireColumn.AutoFit '<<-- Add

标签: vba excel outlook


【解决方案1】:

编辑代码来自

With TempWB.Sheets(1)
    .Cells(1).PasteSpecial Paste:=8
    .Cells(1).PasteSpecial xlPasteValues, , False, False
    .Cells(1).PasteSpecial xlPasteFormats, , False, False
    .Cells(1).Select

更改并添加到 CODE

      Cells(1).Select '<<---- Change
      Cells(1).EntireRow.AutoFit '<<-- Add
      Cells(1).EntireColumn.AutoFit '<<-- Add

或者格式化电子表格并添加列,使数字之间的宽度为0.2,然后是边框

【讨论】:

  • 不幸的是,这让它跳得太远了。是否有可能减少缩进变化的规模?或者甚至只是添加空格?
  • 你可以添加列,使数字之间的宽度为 0.2,然后是边框
猜你喜欢
  • 1970-01-01
  • 2017-03-27
  • 2019-11-04
  • 1970-01-01
  • 1970-01-01
  • 2021-06-06
  • 2019-11-11
  • 1970-01-01
  • 2022-11-22
相关资源
最近更新 更多