简体   繁体   English

VBA:粘贴Excel图表时如何避免日期格式更改

[英]VBA: How to avoid a date format change when Pasting an Excel Chart

I have created 5 graphs and tables that are uploaded to an Email thanks to this Question Pasting an Excel range into an email as a picture 由于这个问题,我已经创建了5个图表和表格,这些图表已上传到电子邮件中。 将Excel范围作为图片粘贴到电子邮件中

Unfortunately, my first graph has a change in the date's format when pasted in Excel already, whereas the second one (and all others) still look exactly similar to what I created. 不幸的是,当我第一个图形已经粘贴到Excel中时,日期格式发生了变化,而第二个图形(以及所有其他图形)看起来仍然与我创建的图形完全相似。 What other way are there to copy paste graphs or what should I look at to make sure this doesn t happen?. 还有什么其他方法可以复制粘贴图,或者应该怎么看才能确保不会发生这种情况?
First Graph with date as number 日期为数字的第一个图 日期为数字的第一张图,第二张图确定

Sheets(2).ChartObjects(1).Chart.CopyPicture
    Dim p2 As Picture
    Set p2 = ActiveSheet.Pictures.Paste

'here date format changed “此处的日期格式已更改

    Sheets(3).ChartObjects(1).Chart.CopyPicture
    Dim p3 As Picture
    Set p3 = ActiveSheet.Pictures.Paste

'here no change '这里没有变化

I finally found an answer from another website: 我终于从另一个网站找到答案:

"The date format problem happens because the axis formats are probably linked to the source data. As long as the source data is in an open workbook, Excel will go and find the format and apply it. To get around this, before copying the chart, double click on the axis, select the Number tab, and uncheck the Link to Source checkbox." “发生日期格式问题是因为轴格式可能已链接到源数据。只要源数据在打开的工作簿中,Excel就会查找并应用格式。要解决此问题,请在复制图表之前,双击该轴,选择“数字”标签,然后取消选中“链接到源代码”复选框。” Jon Peltier 乔恩·佩尔捷

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM