使用定义的名称创建新文件/保存

时间:2018-07-31 16:25:06

标签: excel-vba

我正在使用以下代码,并且在我尝试保存新文件之前一切正常。如您所见,我已经为名称定义了位于原始文件中的范围。一旦进入保存状态,就会出现以下错误:运行时错误438对象不支持此属性或方法。

Dim Directory, FilePath, Name As String
Dim WIPfile, DONEfile As Workbook
Directory = Range("Directory").Value
FilePath = Range("FilePath").Value
Name = Range("Name").Value

Set WIPfile = Application.ThisWorkbook

DisplayAlerts = False


If Range("NI") & Range("Purpose") = "NIAllocation" Then

Sheets("Summ").Select
Sheets("Summ").Copy

Set DONEfile = ActiveWorkbook


With DONEfile
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Rows("7:9").Select
    Selection.Delete Shift:=xlUp
    Range("B7").Select
    Range(Selection, Selection.End(xlToRight)).Select
    With Selection.Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent1
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    With Selection.Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True
    Columns("CU:CU").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Delete Shift:=xlToLeft
    Range("A1").Select
End With

DONEfile.SaveAs _
    WIPfile.Range("FilePath").Value & WIPfile.Range("Name").Value _
    , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

0 个答案:

没有答案