2015-01-13 3 views
0

워크 시트를 새 통합 문서로 저장하려고하지만 초기 통합 문서의 사용자 지정 속성이 상속되지 않습니다.워크 시트 저장 통합 문서 사용자 지정 속성을 상속하지 않음

' Set the workbook properties 
ActiveWorkbook.CustomDocumentProperties.item("customProp1") = variableOne 
ActiveWorkbook.CustomDocumentProperties.item("customProp2") = variableTwo 

' Save the worksheet as a new workbook 
Worksheets("Sheet1").SaveAs FileName:=documentName 
ActiveWorkbook.Close SaveChanges:=True 

나는 광범위한 검색을 수행했으며 이에 대한 해결책을 찾을 수 없습니다.

고마워,

답변

0

나는 해결책이 생각났다. 자동으로 사용자 지정 속성이 필요한 통합 문서를 열고 사용자 지정 속성을 저장하고 저장 한 다음 닫습니다.

Dim app As New Excel.Application 
app.Visible = False 'Visible is False by default, so this isn't necessary 
Dim book As Excel.Workbook 

Set book = app.Workbooks.Add(documentName) 

    With book.CustomDocumentProperties 
     .Add Name:="property1", _ 
      LinkToContent:=False, _ 
      Type:=msoPropertyTypeString, _ 
      Value:="One" 
     .Add Name:="property2", _ 
      LinkToContent:=False, _ 
      Type:=msoPropertyTypeString, _ 
      Value:="two" 
    End With 

    app.DisplayAlerts = False 
    book.Close FileName:=documentName, SaveChanges:=True 
    app.Quit 
Set app = Nothing 
관련 문제