请启用宏. 注意,该代码将强制保存,如果好用,我再作修改为提示是否需要保存. '* +++++++++++++++++++++++++++++ '* Created By I Love You_Word!@ExcelHome 2005-6-7 12:48:13 '仅测试于System: Windows NT Word: 10.0 Language: 2052 '^The Code CopyIn [ThisDocument-ThisDocument]^' '* -----------------------------Option Explicit
Private Sub Document_Close() '在文档退出时引发的事件中 On Error Resume Next With ThisDocument '将光标起始位置赋值给文档变量("START") .Variables("Start").Value = Selection.Start '将光标结束位置赋值给文档变量("END") .Variables("End").Value = Selection.End .Save '保存文档 End With End Sub '---------------------- Private Sub Document_Open() With ThisDocument '如果文档变量的数量少于2,则新增两个文档变量 If .Variables.Count < 2 Then .Variables.Add Name:="Start", Value:=0 .Variables.Add Name:="End", Value:=0 Else '选定区域 .Range(.Variables("Start").Value, .Variables("End").Value).Select End If End With End Sub '----------------------
[此贴子已经被konggs于2007-2-14 7:57:43编辑过] |