smooth 发表于 2013-5-24 21:23:45

请教各位如何将EXCEL宏代码写成AU3?

经过一个星期的仔细琢磨,无法将下面代码写成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

smooth 发表于 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
这样写没有报错,但功能不起作用。

xlj310 发表于 2013-5-25 08:04:04

沙发让你自己占了,哈哈!至少你那些字符串Au3是不认识的!不如将常量赋值到Au3里,会好些!

smooth 发表于 2013-5-25 10:47:07

回复 3# xlj310

不如将常量赋值到Au3里
    请问怎么弄呢?谢谢!

xlj310 发表于 2013-5-25 10:51:31

selection貌似不能直接用在Au3里,最近我也在操作excel
用到selection的地方,还是用Range代替吧!

smooth 发表于 2013-5-25 12:45:15

本帖最后由 smooth 于 2013-5-25 12:46 编辑

selection貌似不能直接用在Au3里,最近我也在操作excel
用到selection的地方,还是用Range代替吧!
xlj310 发表于 2013-5-25 10:51 http://www.autoitx.com/images/common/back.gif
你不是说那几个字符AU3不能识别吗?我用Range()替代selection,也是一样不行的。

xlj310 发表于 2013-5-25 15:31:31

xlRight=-4152
xlCenter=-4108
xlContext=-5002
你把上面这几个字符串用上面的数字代替试一下。
另外我前面说错了一句,Selection在Au3里面是可以用的,我今天自己也在做一个Excel宏转换成Au3的脚本,现在进展还算顺利,有很多问题都在网上找到了答案!
你不妨把你的问题说清楚一点,我有时间帮你转换一下!

smooth 发表于 2013-5-26 17:57:17

回复 7# xlj310

好的,多谢指点!我有时间测试一下。

smooth 发表于 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,其他常量就以此类推了。

kk_lee69 发表于 2013-5-27 20:51:43

{:face (356):} 正解.........寫久了 就知道問題在哪

hzxymkb 发表于 2013-5-28 00:00:57

真不知道宏的使用!
页: [1]
查看完整版本: 请教各位如何将EXCEL宏代码写成AU3?