Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Excel Custom Variables OLE COM
First you need the following .xls file: CUSTPROP.XLS
XLCUSTOMPROPERTIES.WBT
;Winbatch 2005C - ; ;adding/updating Custom Property variables to Excel workbooks ;this example creates a WorkbookVersion property and assigns it ;an initial value of 1, incrementing it each time the workbook is opened. ; ;this is very basic, and uses minimal error handling ; ;Stan Littlefield - August 14, 2005 ;//////////////////////////////////////////////////////////////////////////// IntControl(73,2,0,0,0) ;gosub error handler cXLS=StrCat(DirScript(),"custprop.xls") If ! FileExist(cXLS) Then Exit ver= "WorkbookVersion" ;change for your own tests ;variable types that can be encoded to Custom Properties msoPropertyTypeNumber =1 msoPropertyTypeBoolean =2 msoPropertyTypeDate =3 msoPropertyTypeString =4 msoPropertyTypeFloat =5 val=1 n=0 oXL = CreateObject("Excel.Application") If oXL == 0 Then Exit oXL.Visible = 1 oXL.ScreenUpdating = 1 oXL.UserControl = 1 oXL.DisplayAlerts = 0 oXL.WorkBooks.Open(cXLS) oWS=oXL.ActiveWorkbook.Worksheets(1) oWS.Activate() ;initial look for Custom Property ;will generate error 1261 if it doesn't exists oProp=oXL.ActiveWorkbook.CustomDocumentProperties(ver) :chk IntControl(73,2,0,0,0) If n==1261 ;error return code or present value of n oXL.ActiveWorkbook.CustomDocumentProperties.Add(::Name=ver,LinkToContent=@FALSE,Type=msoPropertyTypeNumber,Value=val) Else val = oXL.ActiveWorkbook.CustomDocumentProperties(ver).Value val=val+1 oXL.ActiveWorkbook.CustomDocumentProperties(ver).Value = val EndIf oXL.ActiveWorkBook.Save() :End oXL.Quit() oXL=0 Display(2,"Current WorkBoook Version",val) Exit :WBERRORHANDLER n=LastError() Message("Last Error",n) Return ;/////////////////////////////////////////////////////////////////////////////////
Article ID: W17152
File Created: 2019:08:14:09:27:28
Last Updated: 2019:08:14:09:27:28