如何将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代码? 重新用AU3写吧,不过我觉得VBA可能更方便一些,毕竟很多功能AU3并没有,比如打印... #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)
你试下,无测试过
#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
非常感谢,学到很多知识,谢谢两位!!
页:
[1]