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

查看:523
本文介绍了使用 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/en-us/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天全站免登陆