tuanyuan_au3 发表于 2024-4-20 13:04:49

如何将VBA代码转成au3运行?

本帖最后由 tuanyuan_au3 于 2024-4-20 16:31 编辑

Sub 宏1()
'
' 宏1 宏
'

'
    Range("A1:J1").Select
    ActiveCell.FormulaR1C1 = "2024年4月明细"
    With ActiveCell.Characters(Start:=1, Length:=14).Font
      .Name = "宋体"
      .FontStyle = "加粗"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      .TintAndShade = 0
      .ThemeFont = xlThemeFontNone
    End With
    With ActiveCell.Characters(Start:=15, Length:=13).Font
      .Name = "宋体"
      .FontStyle = "加粗"
      .Size = 9
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ColorIndex = xlAutomatic
      .TintAndShade = 0
      .ThemeFont = xlThemeFontNone
    End With
    Range("C2").Select
End Sub

怎么把上面的代码转变成au3代码?

邪恶海盗 发表于 2024-4-20 14:29:13

重新用AU3写吧,不过我觉得VBA可能更方便一些,毕竟很多功能AU3并没有,比如打印...

pchome2000 发表于 2024-4-20 20:09:37

#include <Excel.au3>

; 启动Excel应用程序
Local $oExcel = _Excel_Open()

If @error Then
    MsgBox(0, "Error", "Failed to start Excel.")
    Exit
EndIf

; 打开工作簿
Local $oWorkbook = _Excel_BookOpen($oExcel, "路径\你的工作簿.xlsx")

If @error Then
    MsgBox(0, "Error", "Failed to open workbook.")
    _Excel_Close($oExcel)
    Exit
EndIf

; 激活工作表
_Excel_SheetActivate($oWorkbook, "Sheet1")

; 设置单元格内容和格式
_Excel_RangeWrite($oWorkbook, Default, "2024年4月明细", "A1")
_Excel_RangeFont($oWorkbook, Default, "A1", "宋体", 16, True, False, False, False, 0)

_Excel_RangeWrite($oWorkbook, Default, "其他文本", "A1", Default, Default, Default, 14)
_Excel_RangeFont($oWorkbook, Default, "A1", "宋体", 9, True, False, False, False, 0, Default, 14)

; 关闭工作簿并退出Excel应用程序
_Excel_BookClose($oWorkbook)
_Excel_Close($oExcel)


你试下,无测试过

zghwelcome 发表于 2024-4-20 21:27:54



#include <Excel.au3>
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookNew($oExcel)
Local Const $xlUnderlineStyleNone = -4142
Local Const $xlAutomatic = -4105
Local Const $xlThemeFontNone = 0
$oExcel.Range("A1:J1").Select
$oExcel.ActiveCell.FormulaR1C1 = "2024年4月明细"
Local $Start = 1, $Length = 14
With $oExcel.ActiveCell.Characters($Start, $Length).Font
        .Name = "宋体"
        .FontStyle = "加粗"
        .Size = 16
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = $xlUnderlineStyleNone
        .ColorIndex = $xlAutomatic
        .TintAndShade = 0
        .ThemeFont = $xlThemeFontNone
EndWith
$Start = 15
$Length = 13
With $oExcel.ActiveCell.Characters($Start, $Length).Font
        .Name = "宋体"
        .FontStyle = "加粗"
        .Size = 9
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = $xlUnderlineStyleNone
        .ColorIndex = $xlAutomatic
        .TintAndShade = 0
        .ThemeFont = $xlThemeFontNone
EndWith
$oExcel.Range("C2").Select




tuanyuan_au3 发表于 2024-4-21 13:11:13

非常感谢,学到很多知识,谢谢两位!!
页: [1]
查看完整版本: 如何将VBA代码转成au3运行?