即使设置为msoTextureGranite,Shape.FillFormat.presetTexture也始终显示-2(msoPresetTextureMixed)

时间:2018-03-14 17:53:26

标签: vba powerpoint shape

我尝试使用VBA宏克隆从源形状sourceSh到目标形状targetSh的PowerPoint 2010形状的填充;只有填充,否则Shape.PickUp()Shape.Apply()会这样做。

适用于某些情况,例如实心填充和渐变,但当源形状是内置纹理(如msoTextureGranite)时,则属性Shape.Fill.PresetTexture始终返回msoPresetTextureMixed。所以下面的代码崩溃了:

'sourceSh, targetSh initiallized before as Shape
'crashes, because the value of sourceSh.Fill.PresetTexture is msoPresetTexturemixed
Call targetSh.Fill.PresetTextured(sourceSh.Fill.PresetTexture)

'even this is unexpected..
targetSh.Fill.PresetTextured(msoTextureGranite)
'now the read only property targetSh.Fill.PresetTexture is expected
'to be a positive integer representing msoTextureGranite.
'instead I find -2 what represents msoPresetTextureMixed

有没有人知道解决方案,解决方法,还有别的......?

1 个答案:

答案 0 :(得分:0)

更多代码可以解决问题:     

Sub test()
Dim sh As Shape

    'let's assume, there is at least one shape on current slide
    Set sh = ActiveWindow.View.Slide.Shapes(1)

    Call sh.Fill.Solid ' make FillFormat solid

    Debug.Print sh.Fill.Type ' prints 1 (msoFillSolid)
    Debug.Print sh.Fill.PresetTexture ' prints -2 (msoTextureAlignmentMixed)

    sh.Fill.PresetTextured (msoTextureDenim)

    Debug.Print sh.Fill.Type ' prints 4 (msoFillTextured)
    Debug.Print sh.Fill.PresetTexture ' prints -2 again! (msoTextureAlignmentMixed)

    'This assertion fails, because sh.Fill.PresetTexture <> msoTextureDenim
    Debug.Assert sh.Fill.PresetTexture = msoTextureDenim

End Sub