简体   繁体   中英

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

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. 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." Jon Peltier

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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