显示和隐藏活动图表

时间:2015-09-01 07:27:35

标签: excel vba excel-vba

我有这个代码,允许图表显示和隐藏但是我有太多的图表和硬编码每一个将是一个很大的麻烦。那么是否可以根据活动图表隐藏和显示图表?

我有这段代码,我尝试将 Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\tasks\VSBuild\1.0.13\VSBuild.ps1 C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe "C:\a\12345678\Root\src\Foo.Api\Foo.Api.xproj" /nologo /m /nr:false /fl /flp:"logfile=C:\a\12345678\Root\src\Foo.Api\Foo.Api.xproj.log" /dl:CentralLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /t:Build,FileSystemPublish /p:PublishConfiguration=Release /p:PublishOutputPathNoTrailingSlash=C:\a\12345678\staging/Foo.Api /p:platform="any cpu" /p:configuration="Release" /p:VisualStudioVersion="14.0" Build started 9/1/2015 6:36:28 AM. The target "AfterGenerateAppxManifest" listed in an AfterTargets attribute at "C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\Microsoft.Net.CoreRuntime.targets (68,11)" does not exist in the project, and will be ignored. The target "_GeneratePrisForPortableLibraries" listed in a BeforeTargets attribute at "C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\Microsoft.Net.CoreRuntime.targets (177,11)" does not exist in the project, and will be ignored. The target "AfterGenerateAppxManifest" listed in an AfterTargets attribute at "C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\Microsoft.NetNative.targets (126,11)" does not exist in the project, and will be ignored. The target "AfterGenerateAppxManifest" listed in an AfterTargets attribute at "C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\Microsoft.NetNative.targets (174,11)" does not exist in the project, and will be ignored. The target "BeforeGenerateProjectPriFile" listed in a BeforeTargets attribute at "C:\Program Files (x86)\MSBuild\Microsoft\NuGet\Microsoft.NuGet.targets (149,61)" does not exist in the project, and will be ignored. 1>Project "C:\a\12345678\Root\src\Foo.Api\Foo.Api.xproj" on node 1 (Build;FileSystemPublish target(s)). 1>PrepareForBuild: Creating directory "..\artifacts\bin\Foo.Api\". Creating directory "..\artifacts\obj\Foo.Api\any cpu\Release\". C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(103,5): Error : Your project file uses a different version of the TypeScript compiler and tools than is currently installed on this machine. No compiler was found at C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\1.4\tsc.exe. You may be able to fix this problem by changing the <TypeScriptToolsVersion> element in your project file. 1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(103,5): error : Your project file uses a different version of the TypeScript compiler and tools than is currently installed on this machine. No compiler was found at C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\1.4\tsc.exe. You may be able to fix this problem by changing the <TypeScriptToolsVersion> element in your project file. [C:\a\12345678\Root\src\Foo.Api\Foo.Api.xproj] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(103,5): Error MSB6004: The specified task executable location "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\1.4\tsc.exe" is invalid. 1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(103,5): error MSB6004: The specified task executable location "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\1.4\tsc.exe" is invalid. [C:\a\12345678\Root\src\Foo.Api\Foo.Api.xproj] 1>Done Building Project "C:\a\12345678\Root\src\Foo.Api\Foo.Api.xproj" (Build;FileSystemPublish target(s)) -- FAILED. Build FAILED. "C:\a\12345678\Root\src\Foo.Api\Foo.Api.xproj" (Build;FileSystemPublish target) (1) -> (PreComputeCompileTypeScript target) -> C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(103,5): error : Your project file uses a different version of the TypeScript compiler and tools than is currently installed on this machine. No compiler was found at C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\1.4\tsc.exe. You may be able to fix this problem by changing the <TypeScriptToolsVersion> element in your project file. [C:\a\12345678\Root\src\Foo.Api\Foo.Api.xproj] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(103,5): error MSB6004: The specified task executable location "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\1.4\tsc.exe" is invalid. [C:\a\12345678\Root\src\Foo.Api\Foo.Api.xproj] 0 Warning(s) 2 Error(s) Time Elapsed 00:00:01.81 替换为Chartobjects("Chart4"),但它说对象不支持该属性。任何替代方法可以实现这一点或我的代码有什么问题吗?提前谢谢!

ActiveChart

3 个答案:

答案 0 :(得分:2)

ActiveChart引用Chart对象,它是ChartObject对象的成员。你的代码应该是:

With ActiveChart.Parent
    .Visible = Not .Visible
End With

答案 1 :(得分:1)

您可以遍历图表对象以显示或隐藏所有这些对象以节省时间并输入:

Option Explicit

Sub HideAllChartsInSheet1()
    Dim oChartObject As ChartObject

    For Each oChartObject In Sheet1.ChartObjects
        oChartObject.Visible = False
    Next

    Set oChartObject = Nothing
End Sub

Sheet1替换为对实际Worksheet对象的引用,当然使用oChartObject.Visible = True来显示ChartObjects。

修改: 让我们更改子以修改特定的图表对象:

Option Explicit

Sub ChartVisible(psName As String, pbVisible As Boolean)
    Dim oChartObject As ChartObject

    For Each oChartObject In Sheet1.ChartObjects
        If UCase(oChartObject.Name) = UCase(psName) Then
            oChartObject.Visible = pbVisible
        End If
    Next

    Set oChartObject = Nothing
End Sub

示例:使用以下内容隐藏&#34;图4&#34;在Sheet1上:

Call ChartVisible("Chart 4", False)

答案 2 :(得分:0)

您只需选择图表然后隐藏它:

ActiveSheet.ChartObjects("Chart 1").Activate
     Selection.Visible = false