PDA

View Full Version : automation error



lior03
01-21-2006, 09:45 PM
hello
while using the following code i get an automation error.
no error number specidied.

MsgBox "things to know about this workbook:" & vbLf & _
"1." & "application name: " & ActiveWorkbook.BuiltinDocumentProperties("Application Name") & vbLf & _
"2." & "author name: " & ActiveWorkbook.BuiltinDocumentProperties("Author") & vbLf & _
"3." & "created at: " & ActiveWorkbook.BuiltinDocumentProperties("Creation Date") & vbLf & _
"4." & "last printed at: " & ActiveWorkbook.BuiltinDocumentProperties("Last Print Date") & vbLf & _
"5." & "last saved at: " & ActiveWorkbook.BuiltinDocumentProperties("Last Save Time"), vbInformation, "valueable info"

what went wrong
thanks

Norie
01-22-2006, 12:28 AM
Do these document properties actually exist when you try this code?

I can't seem to find a 'Last Print Date' property.

strText = "things to know about this workbook:" & vbLf
strText = strText & "1." & "application name: " & ActiveWorkbook.BuiltinDocumentProperties("Application Name")
strText = strText & "2." & "author name: " & ActiveWorkbook.BuiltinDocumentProperties("Author")
strText = strText & "3." & "created at: " & ActiveWorkbook.BuiltinDocumentProperties("Creation Date")
'strtext = strtext & "4." & "last printed at: " & ActiveWorkbook.BuiltinDocumentProperties("Last Print Date")
strText = strText & "5." & "last saved at: " & ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
MsgBox strText

Bob Phillips
01-22-2006, 04:16 AM
Norie,

There is a Last Print Date property, and it works fine, but note comments below.

Moshe,

You have to be careful, because with some properties, Last Print Date is a prime example, it will fail if the workbook has never been printed. So you need to wrap it in error handling to see if it is okya.

lior03
01-22-2006, 05:20 AM
my exld(iamond)

can you elaboreate.an example please.
thanks

Bob Phillips
01-22-2006, 08:54 AM
Something like this


Sub moshe()
Dim aryProps
Dim aryTxt
Dim sMsg As String
Dim sTmp
Dim i As Long

aryTxt = Array("1. application name: ", "2. author name: ", _
"3. created at: ", "4. last printed at: ", _
"5. last saved at: ")
aryProps = Array("Application Name", "Author", _
"Creation Date", "Last Print Date", _
"Last Save Time")

With ActiveWorkbook
sMsg = "things to know about this workbook:" & vbNewLine
For i = 0 To 4
On Error Resume Next
sTmp = .BuiltinDocumentProperties(aryProps(i))
On Error GoTo 0
sMsg = sMsg & aryTxt(i)
If sTmp <> "" Then
sMsg = sMsg & Space(30 - Len(aryTxt(i))) & sTmp & vbNewLine
Else
sMsg = sMsg & Space(30 - Len(aryTxt(i))) & " - property not set" & vbNewLine
End If
Next i
End With

MsgBox sMsg
End Sub

Norie
01-22-2006, 09:39 AM
xld

So the Last Print Date property only comes into existence after the document is printed?

Or is it just not populated?

Bob Phillips
01-22-2006, 10:39 AM
xld

So the Last Print Date property only comes into existence after the document is printed?

Or is it just not populated?

Hi Norie,

No the property exists, even if the workbook has not been printed,
if you look at the BuiltinDocumentproperties collection, you will see it as one of the items. But, the value is not resolvable until after it has been printed, it errors. The simple On Error Resum Next ... On Error Goto 0 can trap it.

BTW, Last Save Time is the same ilk.