更简单一些的:
请将以下代码复制于NORMAL.DOT的THISDOCUMENT模块下,这是利用模板的打开事件进行自动操作的一个宏,你可以直接选定你想要打开的文件右击打开也可以,在WORD中,使用文件打开也可以,你可以同时选定多个文件.
至于楼主的红色代码部分,这是录制宏时所得,你使用的是自动套用表格格式,由于本过程中只有一个单元格的表格,这些代码没有意义,但网格型是规范其边框线的,可以使用. Private Sub Document_Open() Dim myName As String, atable As Table Application.ScreenUpdating = False With ActiveDocument myName = Mid(.Name, 1, 4) Select Case myName Case "银河财经" myName = "cjnc" Case "银河资本" myName = "zbnc" Case "银河高端" myName = "gdnc" Case "公司研究" myName = "gsyjsl20" End Select .Content.Cut .Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _ 1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _ wdAutoFitFixed With .Tables(1) If Not .Style = "网格型" Then .Style = "网格型" .Cell(1, 1).Range.Paste End With For Each atable In .Tables atable.Rows.Alignment = wdAlignRowCenter Next .Tables(1).Columns(1).SetWidth ColumnWidth:=547.55, RulerStyle:=wdAdjustNone .SaveAs FileName:="C:\Documents and Settings\whcj\桌面\当日工作\" & myName & Format(VBA.Date, "yymmdd") & ".htm", FileFormat:= wdFormatHTML End With Application.ScreenUpdating = True End Sub
|