This applies to Excel - but the steps and procedures are identical in Word. I would search and replace Word for Excel but the code samples wouldn't make sense.
这适用于Excel - 但步骤和过程在Word中是相同的。我会搜索并替换Word for Excel,但代码示例没有意义。
Record the steps in excel macro recorder. You have to rewrite it a bit because it uses a type of syntax that vbs doesn't.
在excel宏录制器中记录步骤。你必须重写它,因为它使用了一种vbs没有的语法。
This applies (I don't have a medium9) xlRangeAutoFormatAccounting4 in vba.
这适用于(我没有medium9)xlRangeAutoFormatAccounting4在vba中。
Selection.AutoFormat Format:=xlRangeAutoFormatAccounting4, Number:=True, _
Font:=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True
So first look up constants in vba's object browser. xlRangeAutoFormatAccounting4 = 17
所以首先在vba的对象浏览器中查找常量。 xlRangeAutoFormatAccounting4 = 17
Then look the function up in object browser and look at the bottom for the function definition,.
然后在对象浏览器中查看该函数,并查看函数定义的底部。
Function AutoFormat([Format As XlRangeAutoFormat = xlRangeAutoFormatClassic1], [Number], [Font], [Alignment], [Border], [Pattern], [Width])
So the vba becomes in vbs (and vbs works in vba) (and as you can see you can work out the correct way without needing to look the function up usually)
所以vba变成了vbs(和vbs在vba中工作)(正如你所看到的,你可以通过正确的方式计算出来,而不需要通常查看函数)
Selection.AutoFormat 17, True, True, True,True, True, True
So your code becomes
所以你的代码变成了
objXLWs.Range("A3").CurrentRegion.Select.AutoFormat 17, True, True, True,True, True, True
You are using Excel and you can record it in Excel and have Excel write your code.
您正在使用Excel,您可以将其记录在Excel中并让Excel编写您的代码。
Alt + T, M, R
Alt + T,M,R
then Home key then Up Arrow. Stop recording.
然后是Home键然后向上箭头。停止录音。
Look what Excel wrote
看看Excel写的是什么
Selection.End(xlUp).Select
or if you had of recorded Go To dialog
或者如果您有录制的“转到”对话框
Application.Goto Reference:="R1C1"
or if you had of recorded Ctrl + Home
或者如果您有录制的Ctrl + Home
Range("A1").Select