dsolefile - (Excelで)エラー値が存在しない場合の取り扱い
質問
私は、彼らが存在しない場合は、ドキュメントのプロパティを更新し、新しいエントリを作成しようとしています。
しかし、 事のこのタイプは動作しません。
Set objDocProps = DSO.GetDocumentProperties(sfilename:=FileName)
With objDocProps
If .CustomProperties("ABC") Is Nothing Then
'create it here
と私はそこにエラーハンドラを置く場合 それはbarfsどちらかがロックされているか、接続を失ったように、
errhandler:
Select Case Err.Number
Case -2147220987 ' missing custom property
Debug.Print "missing custom property"
With objDocProps
.CustomProperties("ABC").Value = "banana!"
解決 2
名前でCUSTOMPROPERTIESにアクセスしようとすると問題があるように見える。
私が実装している溶液に値を設定(またはそれがない場合は新しいものを追加する)ためにこれを使用し、次いで、(存在する場合)項目のインデックスを決定するためにCustomProperyコレクションを反復することである
を渡し:カスタムプロパティオブジェクト、あなたがそれを移入したいあなたが移入するエントリと値を
Sub UpsertEntry(objCustomProps, entryname, entryvalue)
'update the custom property with value supplied
On Error Resume Next
Dim icount
Dim iindex
For icount = 1 To objCustomProps.Count
If objCustomProps.Item(icount).name = entryname Then
iindex = icount
Exit For
Else
iindex = 0
End If
Next
If iindex = 0 Then 'no custom property found
objCustomProps.Add entryname, entryvalue
Wscript.Echo " Adding [" & entryname & ":" & entryvalue & "]"
Else
objCustomProps.Item(iindex).Value = entryvalue
Wscript.Echo " Changing [" & entryname & ":" & entryvalue & "]"
End If
On Error GoTo 0
End Sub
他のヒント
あなたの代わりに、適切なExcelワークブックのためCustomDocumentProperties
コレクションを使用してもらえますか?あなたがそれを見つけた場合は、その後、ちょうどコレクションを反復処理し、プロパティを編集することができます。それはあなたがそのプロパティを作成することができます存在しない場合は、
所属していません StackOverflow