是否可以使用 VBA 访问 Word 中的"IEEE new reference window"?



使用VBA,是否可以打开在Word(2013-2019)中添加新的IEEE参考时显示的窗口,并访问关闭它时填写的值的字段?

这是一个窗口,要求出版类型(书,期刊…),并在此基础上呈现不同的文本框来填充(作者,标题,出版商…)

可能沿着这些行(即不是工作代码,只是一个大纲):

' Declare some variables
Dim result As Long
Dim sourceCount As Long
Dim mySource As Source
' record the Source count pre-dialog
sourceCount = ActiveDocument.Bibliography.Sources.Count
' Set the Bibliographic Style to IEEE
ActiveDocument.Bibliography.BibliographyStyle = "IEEE"
' Display or Show the Create Source Dialog box
result = Dialogs(wdWordDialog.wdDialogCreateSource).Display
' .Show and .Display *should in theory * return different values
' depending on whther the user clicked OK, Cancel, the dialog's
' Close box etc.but on Windows Word the returned value 
' always seems to be 0. On Mac Word that seems to work OK.
' So actually you might as well get rid of 'result' and use
' Dialogs(WdWordDialog.wdDialogCreateSource).Display
' so see if any new entries have been added
If ActiveDocument.Bibliography.Sources.Count > sourceCount Then
' There's a new entry. For the sake of argument, assume that the newest Source is the last in the list

Set mySource = ActiveDocument.Bibliography.Sources(ActiveDocument.Bibliography.Sources.Count)
' At this point, it probably helps to look at the XML of the new source, e.g. 
Debug.Print mySource.XML
' Because the XML only contains the elements corresponding to the
' fields that the user filled in.
' Perhaps the Tag field is always present - I have not checked.
' You can try to retrieve the value of a particular field using e.g.
Dim author As String
author = mySource.Field("author")
' but if there is no author element in the XML, that will raise an error
; i.e. you'll probably need some On Error Resume Next handling.
' To use that approach you have to know the field names for every
' possible field in any type of IEEE source, and/or what fields are
' allowed in each type of source. 
' Not sure the Word object model will help you there.
' **new material**
' All the possible field names and the corresponding XML
' element names are listed in a file called bibform.xml
' in the Microsoft Office program folder structure.
' On my Windows system, that's in 
' C:Program FilesMicrosoft OfficerootOffice161033Bibliography
' On Mac, it's inside the app's package, e.g. the US English
' version is in 
' Application/Microsoft Word/Contents/Resources/en.lproj
' There are different bibform.xml files for different
' (human) languages but the XML element names are the same
' for every language.
' So perhaps a better approach would be to parse the XML for 
' the new Source and discover what fields are actually in there. 
' I'm not going to try that here.
Set mySource = Nothing
End If

如果发现最近添加的源并不总是这个

ActiveDocument.Bibliography.Sources(ActiveDocument.Bibliography.Sources.Count)

那么你可能需要做一些像

  • 在显示
  • 对话框之前创建一个源列表显示对话框
  • 如果有一个新的源,通过比较现有的列表来确定它是哪一个

没有进一步的测试,甚至不明显,新的源的标签/标签名称是唯一的。

指出:

  • MacWord似乎以相同的方式工作,除了上面的注释。
  • ActiveDocument.Bibliography。bibligraphystyle = "假设你有未修改的Office/Word安装,并安装了标准的IEEE Style。

相关内容

  • 没有找到相关文章

最新更新