作为非程序员,这是我的开始,非VBA,关于如何复制/粘贴每个段落的第一句话的想法:
Dim Terminalpoint as String
我可以使用VBA吗?我该如何开始?
答案 0 :(得分:2)
以下是从文档中的每个段落中提取第一个 SENTENCE 的示例。这将是从Word应用程序中编写和调用的代码。
Sub test()
Dim doc As Document
Dim p As Paragraph
Dim s As String
Set doc = ActiveDocument
For Each p In doc.Paragraphs
Debug.Print p.Range.Sentences(1)
Next
End Sub
从Excel中,一个简单的例程来获取每个第一句并将其放在活动Excel工作簿的 new 工作表中:
Sub GetSentences()
'Word objects
Dim wdApp as Object
Dim doc as Object
Dim p as Object
Dim s as String
Dim ws as Worksheet
Set wdApp = CreateObject("Word.Application")
Set doc = wdApp.Documents.Open("c:\your filename.docx")
For each p in doc.Paragraphs
Set ws = Worksheets.Add
ws.Range("A1").Value = p.Range.Sentences(1)
Next
End Sub