找回密码
 加入
搜索
查看: 4140|回复: 10

[AU3基础] 请教各位如何将EXCEL宏代码写成AU3?

  [复制链接]
发表于 2013-5-24 21:23:45 | 显示全部楼层 |阅读模式
经过一个星期的仔细琢磨,无法将下面代码写成AU3格式,请教各位谢谢!
Range("C2:H13").Select
    With Selection
        .HorizontalAlignment = xlRight
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Range("C1:H1").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With

    Range("A1:H13").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
 楼主| 发表于 2013-5-25 07:23:26 | 显示全部楼层
$oExcel.Range("C2:H13").Select
    With $oExcel.Selection
        .HorizontalAlignment = "xlRight"
        .VerticalAlignment = "xlCenter"
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = "xlContext"
        .MergeCells = False
    EndWith
这样写没有报错,但功能不起作用。
发表于 2013-5-25 08:04:04 | 显示全部楼层
沙发让你自己占了,哈哈!至少你那些字符串Au3是不认识的!不如将常量赋值到Au3里,会好些!
 楼主| 发表于 2013-5-25 10:47:07 | 显示全部楼层
回复 3# xlj310

不如将常量赋值到Au3里

    请问怎么弄呢?谢谢!
发表于 2013-5-25 10:51:31 | 显示全部楼层
selection貌似不能直接用在Au3里,最近我也在操作excel
用到selection的地方,还是用Range代替吧!
 楼主| 发表于 2013-5-25 12:45:15 | 显示全部楼层
本帖最后由 smooth 于 2013-5-25 12:46 编辑
selection貌似不能直接用在Au3里,最近我也在操作excel
用到selection的地方,还是用Range代替吧!
xlj310 发表于 2013-5-25 10:51

你不是说那几个字符AU3不能识别吗?我用Range()替代selection,也是一样不行的。
发表于 2013-5-25 15:31:31 | 显示全部楼层
xlRight=-4152
xlCenter=-4108
xlContext=-5002
你把上面这几个字符串用上面的数字代替试一下。
另外我前面说错了一句,Selection在Au3里面是可以用的,我今天自己也在做一个Excel宏转换成Au3的脚本,现在进展还算顺利,有很多问题都在网上找到了答案!
你不妨把你的问题说清楚一点,我有时间帮你转换一下!
 楼主| 发表于 2013-5-26 17:57:17 | 显示全部楼层
回复 7# xlj310

好的,多谢指点!我有时间测试一下。
 楼主| 发表于 2013-5-27 20:45:47 | 显示全部楼层
我知道问题的所在了,xlRight,xlCenter,xlContext……,这些属于宏常量,在宏里可以运行,但是到了AU3是无法识别的,包括放入VB也是无法识别的,唯一的办法将它们代表的常量数值找出来。如xlRight=-4152,xlCenter=-4108,xlContext=-5002。那怎么知道这些常量代表的数值呢?方法是:新建一段宏,写入形如:Range("C1").Value = xlContinuous,这样将在C1单元格,显示1,表示常量xlContinuous代表的数值为1,其他常量就以此类推了。
发表于 2013-5-27 20:51:43 | 显示全部楼层
正解.........寫久了 就知道問題在哪
发表于 2013-5-28 00:00:57 | 显示全部楼层
真不知道宏的使用!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-16 21:45 , Processed in 0.082787 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表