复制和粘贴格式,包括单元格的颜色 VBA Excel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43112386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy and paste format including colour of cells VBA Excel
提问by Ninja Dude
wbTarget.Sheets("Sheet1").Range("A1:W79").Value = wb.Sheets(wsSource.Name).Range("A1:W79").Value
I have this code which works pasting the values of wb.Sheets(wsSource.Name) to wbTarget sheets. However, it only pastes the value and not the format/color. How do I paste it including the fonts, color of cell.
我有这段代码可以将 wb.Sheets(wsSource.Name) 的值粘贴到 wbTarget 工作表。但是,它只粘贴值而不是格式/颜色。如何粘贴它,包括字体、单元格颜色。
回答by Shai Rado
You need to use Copy, and PasteSpecial xlValuesand PasteSpecial xlFormats.
您需要使用Copy,PasteSpecial xlValues和PasteSpecial xlFormats。
' Copy
wb.Sheets(wsSource.Name).Range("A1:W79").Copy
' Paste Special
wbTarget.Sheets("Sheet1").Range("A1:W79").PasteSpecial xlValues
wbTarget.Sheets("Sheet1").Range("A1:W79").PasteSpecial xlFormats
Read about Range.PasteSpecialhere MSDN
在Range.PasteSpecial这里阅读MSDN

