工作簿之间的Excel VBA复制格式 [英] Excel VBA copy format between workbooks

查看:663
本文介绍了工作簿之间的Excel VBA复制格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮忙解决如何将格式(列宽,颜色......)从一个Excel .xls中的范围复制到另一个.xls中的相等范围。目前使用以下格式



工作表(" file1.xls!sheet")。范围(" A1:IL36")。 _
目的地:=工作表(" file2.xls!sheet")。范围(" A1:IL36")



在一个.xls内的工作表之间工作,但不复制格式,只有内容



r.con

解决方案

要复制列宽,我认为您需要复制整个列,然后选择目标工作簿中的整个列并执行PasteSpecial。



Sub Test()

'复制范围及其格式
工作簿("Source.xls")。表格("Sheet1")。范围("A1:C40") ).Copy
工作簿("Destination.xls")。表格("Sheet1")。范围("A1:C40")。PasteSpecial(xlPasteAll)

'复制列宽和他们的格式
工作簿("Source.xls")。表格("Sheet1")。朗e("A:C")。复制
工作簿("Destination.xls")。表格("Sheet1")。范围("A:C")。PasteSpecial(xlPasteFormats)
< br>结束子



< BR>

Can anyone help work out how to copy the format (column width, colour,...) from a range in one Excel .xls to an equal range in another .xls.  Currently using the following format

 

Worksheets("file1.xls!sheet").Range("A1:IL36").Copy _
        Destination:=Worksheets("file2.xls!sheet").Range("A1:IL36")

 

Works among sheets within one .xls but does not copy format, only contents

 

r.con

解决方案

To copy the column widths I think you need to copy the entire column and then select the entire column in the destination workbook and do a PasteSpecial.

Something like

Sub Test()

'copies the range and its formats
Workbooks("Source.xls").Sheets("Sheet1").Range("A1:C40").Copy
Workbooks("Destination.xls").Sheets("Sheet1").Range("A1:C40").PasteSpecial (xlPasteAll)

'copies the column widths and their formats
Workbooks("Source.xls").Sheets("Sheet1").Range("A:C").Copy
Workbooks("Destination.xls").Sheets("Sheet1").Range("A:C").PasteSpecial (xlPasteFormats)

End Sub




这篇关于工作簿之间的Excel VBA复制格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆