【发布时间】:2021-02-24 07:10:50
【问题描述】:
美好的一天!
我有一个获取文章标题的主循环,它是描述和正文。我通过他们的 Word 风格得到它们。 我还有一个在主循环结束时调用的函数。我有一本字典在里面。它完成了它的工作。现在我需要创建另一个字典或替代它。我可以在哪里获得 Key - 文章的描述和 Item - 文章的标题。意味着我可以有多个具有相同项目的键。
现在我每次调用 dictionary2.add Key:=descriptionVariable Item:=TitleOfAnArticle(titleOfTheWord) 时都会遇到问题,我会覆盖现有值,我知道原因。只是不知道如何绕过它。有什么想法吗?
For Each StyleInWord in ActiveDocument.Paragraphs
If StyleInWord.Style = "Style of The Title" Then
tileOfTheWord = StyleInWord.Range 'here i store the paragraph.
End If
'The rest of the code works same as above, with its features.
Call TheFunction
Next
Function Theunction(titleOfTheWord)
'I here create a dictionary with key - The Title of The Article; Item - Item is a path to the image of that particular Title
End Function
【问题讨论】:
-
你的意思是一键多值?您可以将值放在数组或集合中,并将其存储为字典值。这将有助于显示更多现有代码。
-
@TimWilliams 不,我的意思是同一个项目有很多键。我真的做到了。
-
顺便说一下,Word 有一个内置样式“标题”。它还有一个内置的文档属性“标题”,既可以在 vba 中访问,也可以使用 Quick Parts > Document Property 菜单访问。
标签: vba ms-word powerpoint