使用VBA将一个Excel工作表的格式复制到另一个Excel工作表 [英] Copying Format of one excel sheet to another excel worksheet using VBA

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

问题描述

是否可以使用VBA将一个Excel工作表的格式复制到另一工作表中.

Is it possible to copy format of one excel sheet to another worksheet using VBA.

就像手动操作一样,我们可以选择整个工作表,然后单击格式"按钮.然后选择其他工作表和格式将被复制.是否可以通过代码来完成.

Like manually we can do by selecting entire sheet and then click on format button. And then select other worksheet and format will be copied. Is it possible to do by code.

感谢&问候 萨希尔·乔杜里

Thanks & Regards Sahil Chaudhary

推荐答案

绝对.下面是示例代码.

Absolutely. Below is sample code.

请参见 https://msdn.microsoft.com/zh-CN /library/office/ff837425.aspx

Sub Wsh_PasteSpecial()
Dim WshSrc As Worksheet
Dim WshTrg As Worksheet

Rem Set working worksheets
Set WshSrc = ThisWorkbook.Worksheets("Source")
Set WshTrg = ThisWorkbook.Worksheets("Target")

    WshSrc.Cells.Copy
    With WshTrg.Cells
        .PasteSpecial Paste:=xlPasteColumnWidths
        .PasteSpecial Paste:=xlPasteFormats
        .PasteSpecial Paste:=xlPasteFormulasAndNumberFormats
        Application.CutCopyMode = False
    End With    
End Sub

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

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