二级水平X轴VBA的最大比例

时间:2017-01-01 09:53:52

标签: vba

通过以下代码Max。和敏正在设置vba中图表的主要水平X轴的比例;

Sub chart_set()
    Dim objCht As ChartObject
    With ActiveSheet.ChartObjects(1).Chart.Axes(xlValue)
    .MinimumScale = 0
    .MaximumScale = my_max_var
    End With
End Sub

有没有办法设置次要的?

1 个答案:

答案 0 :(得分:2)

首先,下面的代码Set objChtActiveSheet添加到ActiveSheet中的ChartObject(请参阅此处建议如何远离MinimumScale How to avoid using Select in Excel VBA macros

下面的代码将检查是否应用了辅助轴,否则会将其添加到图表中。之后,它会将MaximumScaleOption Explicit Sub chart_set() Dim objCht As ChartObject Dim my_max_var As Long ' just for my tests my_max_var = 1000 ' set chart object Set objCht = ActiveSheet.ChartObjects(1) With objCht With .Chart.Axes(xlValue, xlPrimary) .MinimumScale = 0 .MaximumScale = my_max_var End With ' check if Secondary Axis is applied If .Chart.HasAxis(xlValue, xlSecondary) = False Then .Chart.HasAxis(xlValue, xlSecondary) = True End If ' modify minimum and maximum values of seconday axis With .Chart.Axes(xlValue, xlSecondary) .MinimumScale = 20 .CrossesAt = 20 .MaximumScale = 50 End With End With End Sub 修改为20和50(只是我选择的随机数字)。

<强>代码

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>quiz_mcq</display-name>
    <welcome-file-list>
        <welcome-file>welcome.htm</welcome-file>
    </welcome-file-list>

    <servlet>
          <servlet-name>spring-dispatcher</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

   <servlet-mapping>
      <servlet-name>spring-dispatcher</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>

</web-app>