'------------------------------------------------------------------ ' OpenIMS Microsoft Excel integration for Office 2007 documents (XLSM) ' Version 1.0, 2011/03. ' (c) 2001-201 OpenSesame ICT, all rights reserved. ' See http://www.osict.com/openims/termsofuse.txt for more details. ' Implementation: use this code as embedded module (module under VBAproject) ' Example formula: =OPENIMS_GetMeta("name",RAND()) ' for Dutch Excel versions: =OPENIMS_GetMeta("name";ASELECT()) ' For fields in header/footer: use following code in 'ThisWorkbook': ' (replace "test:..." with own header/footer text) 'Private Sub Workbook_Open() ' Dim sh As Worksheet ' For i = 1 To ActiveWorkbook.Sheets.Count ' Set sh = ActiveWorkbook.Sheets(i) ' With sh.PageSetup ' .LeftHeader = OPENIMS_InsertMetaFieldsInString("test: [[[test]]] [[[test2]]], [[[testtaxo]]]") ' '.CenterHeader = OPENIMS_InsertMetaFieldsInString("") ' '.RightHeader = OPENIMS_InsertMetaFieldsInString("") ' '.LeftFooter = OPENIMS_InsertMetaFieldsInString("") ' '.CenterFooter = OPENIMS_InsertMetaFieldsInString("") ' '.RightFooter = OPENIMS_InsertMetaFieldsInString("") ' End With ' Next i 'End Sub ' ' Requires OpenIMS build 31000 or higher ' The OpenIMS server needs to be configured to add metadata to XSLM files. '------------------------------------------------------------------ Public Function OPENIMS_GetMeta(FieldName As String, Random As Double) OPENIMS_GetMeta = ActiveWorkbook.CustomDocumentProperties("openims_set_" & FieldName) End Function Function OPENIMS_InsertMetaFieldsInString(strin As String) As String ' used for parsing headers and footers Dim found As Boolean, strret As String, c As String, meta As String found = True strret = strin While found a = InStr(strret, "[[[") If a = 0 Then found = False Else b = InStr(a, strret, "]]]") If b = 0 Then found = False Else c = Mid(strret, a + 3, b - a - 3) meta = OPENIMS_GetMeta(c, 0) strtemp = Left(strret, a - 1) & meta & Right(strret, Len(strret) - (b + 2)) strret = strtemp End If End If Wend OPENIMS_InsertMetaFieldsInString = strret End Function