Excel 2007 VBA问题设置轴标题 [英] Excel 2007 VBA Problem setting Axis Title

查看:142
本文介绍了Excel 2007 VBA问题设置轴标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助设置Excel 2007 VBA中的X和Y轴标题。它持续抱怨需要对象:

I need help setting the X and Y axes title inside Excel 2007 VBA. It keeps complaining about "Object required":

Sub macro2()

Dim xAxis As Axis

icount = 1

Charts.Add
Charts(icount).Name = iskewplane & "deg Skew Plane"
Charts(icount).Activate

Set xAxis = Charts(icount).Axes(xlCategory)
With xAxis
    .Axis
    .AxisTitle.Text = "Theta (deg)"
End With

是否有东西我的代码错了?在设置轴名称时,我尝试录制宏,但在名称设置期间宏是空白。

Is there something wrong in my code? I tried recording the macro during setting the axis title name, but the macro is blank during the name setting.

任何帮助都赞赏

推荐答案

您应该使用 Option Explicit ,因为 iCount wasn没有定义, iskewplane 也不是。

You should use Option Explicit because iCount wasn't defined and iskewplane wasn't either.

这是正确的代码:

Sub mac()
    Dim xAxis As Axis
    Dim iCount As Integer
    iCount = 1
    Charts.Add
     Charts(iCount).Name = "deg Skew Plane"
    Charts(iCount).Activate

    Set xAxis = Charts(iCount).Axes(xlCategory)
    With xAxis
        .HasTitle = True
        .AxisTitle.Caption = "Theta (deg)"
    End With
End Sub

这篇关于Excel 2007 VBA问题设置轴标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆