2009-04-03 5 views
0

나는 그들이dsolefile는 - 오류 처리 할 때 값이

존재하지 않는 경우 문서 속성을 업데이트하고 새 항목을 만들려고 해요 그러나 것은 이런 종류의 일을하지 않습니다 (Excel에서) 존재하지 않는

Set objDocProps = DSO.GetDocumentProperties(sfilename:=FileName) 

With objDocProps 
If .CustomProperties("ABC") Is Nothing Then 
'create it here 

그리고 그것이 잠긴 또는

errhandler: 
Select Case Err.Number 
Case -2147220987 ' missing custom property 
Debug.Print "missing custom property" 
With objDocProps 
    .CustomProperties("ABC").Value = "banana!" 

답변

0

이름으로 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 
0

은 사용 할 수 연결을 잃은 중 하나로 barfs이 에 오류 처리기를 넣어 경우 적절한 Excel 통합 문서 모음 대신 CustomDocumentProperties 콜렉션이 필요합니까? 그런 다음 컬렉션을 반복하고 속성을 찾으면 속성을 편집 할 수 있습니다. 존재하지 않으면 속성을 만들 수 있습니다.

+0

CustomDocumentProperties는 Office 개체의 일부인 것처럼 보입니다. dsolefile의 요점은 속성을 읽고 수정하기 위해 사무실을 설치할 필요가 없다는 것입니다. 나는 그것을 사용할 수 없다. –