You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:VBA硬编码条件格式效果时渐变颜色功能失效

硬编码条件格式渐变失效的解决方案求助

现状说明

我找到了一种硬编码条件格式效果的方案,目前能实现颜色和图案的硬编码,但渐变颜色功能无法正常工作。

原始可运行代码

这段代码能正常硬编码条件格式,但仅支持纯色,不支持图案和渐变:

'this block will hard code the applied conditional formatting
For Each cell In rng
    If cell.DisplayFormat.Interior.ColorIndex <> xlNone Then
        cell.Interior.Color = cell.DisplayFormat.Interior.Color
    End If
Next cell

修改后的代码(渐变部分失效)

新增了图案硬编码功能,但渐变相关代码无法生效,失效段已标记:

'this block will hard code the applied conditional formatting
For Each cell In rng
    If cell.DisplayFormat.Interior.ColorIndex <> xlNone Then
        With cell.Interior
            .Color = cell.DisplayFormat.Interior.Color
            .Pattern = cell.DisplayFormat.Interior.Pattern
            '*********** THIS BIT DOESN'T WORK**************
            .Gradient.Degree = cell.DisplayFormat.Interior.Gradient.Degree
            '.Gradient.ColorStops.Clear
            With Gradient.ColorStops.Add(0)
                .Color = cell.DisplayFormat.Interior.Gradient.ColorStops.Add(0).Color
                .TintAndShade = cell.DisplayFormat.Interior.Gradient.ColorStops.Add(0).TintAndShade
            End With
            With Gradient.ColorStops.Add(1)
                .Color = cell.DisplayFormat.Interior.Gradient.ColorStops.Add(1).Color
                .TintAndShade = cell.DisplayFormat.Interior.Gradient.ColorStops.Add(1).TintAndShade
            End With
            '*********** THIS BIT DOESN'T WORK**************
        End With
    End If
Next cell

求助需求

恳请提供能正常硬编码渐变颜色的可行解决方案。

内容的提问来源于stack exchange,提问作者Jack Pennington

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 14:10:02