Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 保存范围中的所有信息,并在以后还原_Vba_Excel - Fatal编程技术网

Vba 保存范围中的所有信息,并在以后还原

Vba 保存范围中的所有信息,并在以后还原,vba,excel,Vba,Excel,有没有办法将字体指定给某个范围 假设我有一个对象myFont。我可以写: with Range("A1").Font .Bold=myFont.Bold .Size=myFont.Size same with other properties end with 但是有很多字体属性。有没有办法做类似的事情 范围(“A1”).Font=myFont?要更改字体属性,请按照以下代码操作。具体来说,要更改范围(“A1”)字体名称,请使用“font.name”

有没有办法将字体指定给某个范围

假设我有一个对象myFont。我可以写:

 with Range("A1").Font
       .Bold=myFont.Bold
       .Size=myFont.Size
       same with other properties
end with
但是有很多字体属性。有没有办法做类似的事情
范围(“A1”).Font=myFont?

要更改字体属性,请按照以下代码操作。具体来说,要更改范围(“A1”)字体名称,请使用“font.name”,如下所示

为了实现这一点,我只需录制一个宏,其中我更改了字体,然后停止宏以查看代码。有时尝试录制宏以查找所需的属性。希望这有帮助

Sub ChangeFontCustomRange()

' Change Font Name

    'Select the Range to change font to
    Range("A1").Select

    'Change font properties, specifically, Font.Name
    With Selection.Font
        .Name = "Calibri" 'Type exact font name here
        .Size = 11
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
End Sub

没有人能做你想做的事。下面是一个可能的快捷方式,但您仍然在迭代每个属性

Dim p, myFont, rng As Range

'populate myFont, rng

For Each p In Array("Bold", "Color", "Size") 'for example
    CallByName rng.Font, p, VbLet, CallByName(myFont, p, VbGet)
Next p

不,范围对象的字体属性是只读的。未测试,但使用
font如何。FontStyle
?Toris,FontStyle仅包含粗体和斜体信息