如何提取/删除每页的第一个单词?
我做了一个邮件合并来创建包含客户信息的动态单词页面。
然后我(通过在网上查找)一个宏将结果文件分成几页,每一页都保存为一个文件。
现在我希望为这些文件提供一些包含客户信息的名称。我用谷歌搜索了一下,我认为(唯一的?)方法是在页面的最开始创建一个包含该信息的合并字段,然后使用宏从页面中提取并删除它,将其放入文件名中。
示例:如果我有一个名为 Stackoverflow 的客户,我想要一个名为 Facture_Stackoverflow.doc 的文件。
我找不到如何从我的页面中选择、提取然后删除第一个单词的方法。
这是我的“分割宏”,它当前仅使用递增的 ID 来命名文件:
Sub DecouperDocument()
Application.Browser.Target = wdBrowsePage
For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
ActiveDocument.Bookmarks("\page").Range.Copy
Documents.Add
Selection.Paste
Selection.TypeBackspace
ChangeFileOpenDirectory "C:\test\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="Facture_" & DocNum & ".doc"
ActiveDocument.Close
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
I did a mailmerge to create dynamic word pages with customer information.
Then I did (by looking on the net) a macro to split the result file into several pages, each page being saved as one file.
Now I'm looking to give those files some names containing customer info. I googled that and I think the (only?) way is to create a mergefield with that info, at the very beginning of the page, then extract and delete it from the page with a macro to put it in file names.
Example: If I have a customer named Stackoverflow I would like to have a file named Facture_Stackoverflow.doc.
I found nowhere how to select, extract and then delete this first word from my page.
Here is my "splitting macro", which currently names the files just with an incremented ID:
Sub DecouperDocument()
Application.Browser.Target = wdBrowsePage
For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
ActiveDocument.Bookmarks("\page").Range.Copy
Documents.Add
Selection.Paste
Selection.TypeBackspace
ChangeFileOpenDirectory "C:\test\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="Facture_" & DocNum & ".doc"
ActiveDocument.Close
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的函数将使您能够提取 Word 文档的第一个单词(并可选择删除它)。
我希望这有帮助。
The function below will enable you to extract the first word (and optionally remove it) of a Word document.
I hope this helps.