If Selection.Fields.Count >= 1 Then Selection.Fields.Update
可用 Type 属性返回选定内容类型(例如,选定内容是一块内容还是一个插入点)。下例当选定内容为插入点时将选定内容变为当前段。
If Selection.Type = wdSelectionIP Then
Selection.Paragraphs(1).Range.Select
End If
可用 Information 属性返回有关选定内容的信息。下例当选定内容在表格中时显示该表格的行数和列数。
If Selection.Information(wdWithInTable) = True Then
MsgBox "Columns = " _
& Selection.Information(wdMaximumNumberOfColumns) _
& vbCr & "Rows = " _
& Selection.Information(wdMaximumNumberOfRows)
End If
可用 Select 方法选定文档中的一个项目。下例选定活动文档中的第一个书签并将其显示为红色。
If ActiveDocument.Bookmarks.Count >= 1 Then
ActiveDocument.Bookmarks(1).Select
Selection.Font.ColorIndex = wdRed
End If
Selection 对象还包括了几种用于扩展或移动当前选定内容的方法。例如,可以将 MoveDown 方法的 Extend 参数设为 wdExtend。下例在活动窗口中选定接下的三段。
With Selection
.StartOf Unit:=wdParagraph, Extend:=wdMove
.MoveDown Unit:=wdParagraph, Count:=3, Extend:=wdExtend
End With
说明
可用 Range 属性从 Selection 对象返回一个 Range 对象。下例将变量 myRange 定义为所选范围。
Set myRange = Selection.Range
记录宏时,宏记录器经常将变化记录到 Selection 对象。下列宏将文档的起始两个词设为加粗格式,并新添一段。
Set myRange = ActiveDocument.Range(Start:=0, _
End:=ActiveDocument.Words(2).End)
myRange.Bold = True
myRange.InsertParagraphAfter
每个窗格中只能有一个 Selection 对象;但在一个文档中可以有多个 Range 对象。一个 Range 对象代表了文档中一个已选定或未选定的范围。用 Range 对象可很方便地进行文档操作。详细内容,请参阅处理 Range 对象。
<%
set wordApp=createobject("word.application")
set wordDoc=createobject("word.document")
strDocFile="..\1.doc"
set wordDoc=wordApp.documents.open(strDocFile)
wordDoc.SaveAs "..\11.doc"
在这里操作你的文档副本,对于内容定位你可以使用Bookmarks定位,也就是说你在模板文件中定义你需要操作内容区域为书签
然后用
if WordDoc.bookmarks.exists("你的书签名称") then
WordDoc.bookmarks("你的书签名称").select
wordApp.selection.xxxxx (这里就是操作selection的内容了,根据需要你可以直接访问
selection的tables, rows, cells, Characters,
columns, Comments,Fields,InlineShapes等等对象结合,
进行你说需要的限定范围内的任何对象集合操作
[包括对象修改,新增,删除,查找等任何功能])
end if
你用strDocContent=wordDoc.content
当然会丢失格式了
wordDoc.close
wordApp.quit '注意,任何操作必须记得调用wordapp的quit,否则将流失系统资源,导致应用服务器被锁定
set wordDoc=nothing
set wordApp=nothing %>
yonghengdizhen:selection对象在ASP中的用法实在不清楚。
ceocio:自己编了一段读取word文件内容,然后以此内容重新生成word文件的代码,如下
<%
set wordApp=createobject("word.application")
set wordDoc=createobject("word.document")
strDocFile="..\1.doc"
set wordDoc=wordApp.documents.open(strDocFile)
strDocContent=wordDoc.content
wordDoc.close
set wordDoc=nothing
set worddoc2=createobject("word.document")
wordDoc2.content=strDocContent
wordDoc2.Application.ActiveDocument.SaveAs "..\11.doc"
wordDoc2.close
set wordDoc2=nothing
set wordApp=nothing %>