工作表另存为不继承工作簿自定义属性

Worksheet SaveAs not inheriting workbook custom properties

我正在尝试将工作表另存为新工作簿,但在这样做时,初始工作簿的自定义属性未被继承。

' 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

我进行了广泛的搜索,但找不到解决方案。

谢谢,

我不确定这是否可行,但我确实想出了一个解决方案。它默默地打开需要自定义属性的工作簿,给它自定义属性,保存它然后关闭它。

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