I'm looking for help in translating a piece of code from Word VBA to AHK. What I've gathered so far is attached below and is all well, besides the last step that return error 0x80020005 – type mismatch. I pretty sure I've seen somewhere mentions that „SetMapping” is unreliable, but I cannot find it. Should be mentioned, that VBA macro is working just fine.
VBA:
Code: Select all
Sub Macro1()
Dim aCC As ContentControl, xPart As CustomXMLPart
Set aCC = ActiveDocument.ContentControls.Add(wdContentControlText)
aCC.Title = "Title"
Set xPart = ActiveDocument.CustomXMLParts.SelectByNamespace("http://schemas.openxmlformats.org/package/2006/metadata/core-properties")(1)
aCC.XMLMapping.SetMapping XPath:="/ns1:coreProperties[1]/ns0:title[1]", Source:=xPart
End Sub
AHK:
Code: Select all
oWord := ComObjActive("Word.Application")
acc := oWord.ActiveDocument.ContentControls.Add(wdContentControlText := 1)
acc.Title := "Title"
xPart := oWord.ActiveDocument.CustomXMLParts.SelectByNamespace("http://schemas.openxmlformats.org/package/2006/metadata/core-properties")(1)
acc.XMLMapping.SetMapping(XPath := "/ns1:coreProperties[1]/ns0:title[1]", Source := xPart)