Excel Built In Properties

Started by spl, October 31, 2024, 08:51:29 AM

Previous topic - Next topic

spl

Maybe not important, but played around with a script from Tech DB to iterate Excel Built In Properties. It was specific to .xls so tried with .xlsx, [and it was also limited to 15 properties]. Below is my attempt to work with attached cats.xlsx saved as zip]. It will fail with an OLE error, but I want to display attached jpg. I think CLR/.NET would be needed to update the script... dunno
XL = "C:\temp\cats.xlsx"
;Open Excel
objXL= ObjectOpen("Excel.Application")
objXL.Visible = @FALSE

;Open XLS file
MyWorkbook = objXL.workbooks
MWO = MyWorkbook.open(XL)

;Get active workbook object
AWB = objXL.activeworkbook
Props = ""
for i = 1 to 15
   bidp = AWB.BuiltinDocumentProperties(i)
   propval = bidp.value
   len = StrLen(propval)
   Props = Props : "Prop %i% length in %docname% is %len% %propval%"
next
ObjectClose(objXL)
Message(XL:" BuiltIn Props",Props)

Stan - formerly stanl [ex-Pundit]

td

The following prevents the error but doesn't explain why only string values are accessible.

XL = "C:\Temp\cats.xlsx"
;Open Excel
objXL= ObjectOpen("Excel.Application")
objXL.Visible = @FALSE

;Open XLS file
MyWorkbook = objXL.workbooks
MWO = MyWorkbook.open(XL)

;Get active workbook object
AWB = objXL.activeworkbook
Props = ""
i = 0
PropEnum = AWB.BuiltinDocumentProperties
foreach bidp in PropEnum
   i += 1
   if  bidp.type == 4  ; String value.
      propval = bidp.value
      len = StrLen(propval)
      Props = Props : "Prop %i% length in %docname% is %len% %propval%":@lf
   endif
next
ObjectClose(objXL)
Message(XL:" BuiltIn Props",Props)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

spl

Thanks for clearing the error. This seems to be more what I was after
XL = "C:\temp\cats.xlsx"
;Open Excel
objXL= ObjectOpen("Excel.Application")
objXL.Visible = @FALSE

;Open XLS file
MyWorkbook = objXL.workbooks
MWO = MyWorkbook.open(XL)

;Get active workbook object
AWB = objXL.activeworkbook
Props = ""
i = 0
PropEnum = AWB.BuiltinDocumentProperties
foreach bidp in PropEnum
   i += 1
   name = bidp.Name
   if  bidp.type == 4  ; String value.
     
      propval = bidp.value
      Props = Props : "%name%: %propval%":@lf
   else
      Props = Props : "%name%: cannot be determined":@lf
   endif
next
ObjectClose(objXL)
Message(XL:" BuiltIn Props",Props)
Stan - formerly stanl [ex-Pundit]

td

MSFT states that a document property will "If the container application doesn't define a value for one of the built-in document properties, reading the Value property for that document property causes an error."

It might explain why the error occurrd in the first place.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

spl

Quote from: td on October 31, 2024, 01:31:51 PMMSFT states that a document property will "If the container application doesn't define a value for one of the built-in document properties, reading the Value property for that document property causes an error."

It might explain why the error occurrd in the first place.

Yes, while the property names are there, document types would not support certain values, hence script them as 'unable to determine'... would assume those properties would iterate in a Word or Powerpoint document. Probably easy to verify.
Stan - formerly stanl [ex-Pundit]

spl

Attached is script with AskFileName() added to display built in properties. Might be suitable for Tech Database.
Stan - formerly stanl [ex-Pundit]