Aracılığıyla paylaş


Nasıl Yapılır: Özel Belge Özelliklerini Oluşturma ve Değiştirme

Yukarıda listelenen Microsoft Office uygulamaları, belgelerde kaydedilen yerleşik özellikler sağlar.Ayrıca, belgeyle kaydetmek istediğiniz ek bilgiler varsa, özel belge özelliklerini oluşturabilir ve değiştirebilirsiniz.

Uygulama hedefi: Bu konudaki bilgiler, şu uygulamalar için belge düzeyi projeler ve uygulama düzeyi projelere yöneliktir: Excel 2013 ve Excel 2010; PowerPoint 2013 ve PowerPoint 2010; Project 2013 ve Project 2010; Word 2013 ve Word 2010. Daha fazla bilgi edinmek için, bkz. Office Uygulaması ve Proje Türüne Göre Kullanılabilir Özellikler.

Özel özelliklerle çalışmak için belgenin CustomDocumentProperties özelliğini kullanın.Örneğin, Microsoft Office Excel için belge düzeyi projesinde ThisWorkbook sınıfının CustomDocumentProperties özelliğini kullanın. Excel için uygulama düzeyi projesinde, Workbook nesnesinin CustomDocumentProperties özelliğini kullanın.Bu özellikler, DocumentProperty nesnelerinin bir koleksiyonu olan DocumentProperties nesnesi döner.Koleksiyonun Item özelliğini, koleksiyon içindeki belirli bir özelliği ismiyle veya diziniyle almak için kullanabilirsiniz.

Aşağıdaki kod örneğinde, belge düzeyi özelleştirmesindeki özel özelliğin nasıl eklendiği ve bir değere nasıl atandığı gösterilir.

video bağlantısı İlgili video gösterimi için bkz: nasıl yapmak ı: Access ve Microsoft Word'de özel belge özelliklerini işlemek?.

Örnek

Sub TestProperties()
    Dim properties As Microsoft.Office.Core.DocumentProperties
    properties = CType(Me.CustomDocumentProperties, Office.DocumentProperties)

    If ReadDocumentProperty("Project Name") <> Nothing Then
        properties("Project Name").Delete()
    End If

    properties.Add("Project Name", False, _
        Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, _
        "White Papers")
End Sub 

Private Function ReadDocumentProperty(ByVal propertyName As String) As String 
    Dim properties As Office.DocumentProperties
    properties = CType(Me.CustomDocumentProperties, Office.DocumentProperties)

    Dim prop As Office.DocumentProperty

    For Each prop In properties
        If prop.Name = propertyName Then 
            Return prop.Value.ToString()
        End If 
    Next 

    Return Nothing 
End Function
void TestProperties()
{
    Microsoft.Office.Core.DocumentProperties properties;
    properties = (Office.DocumentProperties)this.CustomDocumentProperties;

    if (ReadDocumentProperty("Project Name") != null)
    {
        properties["Project Name"].Delete();
    }

    properties.Add("Project Name", false,
        Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString,
        "White Papers");
}

private string ReadDocumentProperty(string propertyName)
{
    Office.DocumentProperties properties;
    properties = (Office.DocumentProperties)this.CustomDocumentProperties;

    foreach (Office.DocumentProperty prop in properties)
    {
        if (prop.Name == propertyName)
        {
            return prop.Value.ToString();
        }
    }
    return null;
}

Güçlü Programlama

Tanımlanmamış özellikler için Value özelliğine erişmeye çalışmak aykırı bir durum yaratır.

Ayrıca bkz.

Görevler

Nasıl Yapılır: Belge Özelliklerinden Okuma ve Yazma

Diğer Kaynaklar

Uygulama Düzeyi Eklentileri Programlama

Belge Düzeyi Özelleştirmelerini Programlama