复制时将“下拉列表”格式化为正常值

时间:2018-11-08 06:31:21

标签: excel vba formatting

我有一本工作簿,我将从中提取3张特定的图纸。问题在于,在此工作簿中,一个特定的单元格(工作表“ country 2019”中的B1)是一个下拉列表。 当我打开新生成的文件(仅包含3张纸)时,此B1单元会生成错误

  

此工作簿包含一个或多个无法更新的链接。

我可以通过从“名称管理器”中删除链接并保存来手动断开链接,但问题是:

我可以在代码中添加一行以格式化此单元格,然后再生成新工作簿吗?

Sub TwoSheetsAndYourOut()
    Dim NewName As String
    Dim nm As Name
    Dim ws As Worksheet

    If MsgBox("Copy specific sheets to a new workbook" & vbCr & _
    "New sheets will be pasted as values, named ranges removed" _
    , vbYesNo, "NewCopy") = vbNo Then Exit Sub

    With Application
        .ScreenUpdating = False

         '       Copy specific sheets
         '       *SET THE SHEET NAMES TO COPY BELOW*
         '       Array("Sheet Name", "Another sheet name", "And Another"))
         '       Sheet names go inside quotes, seperated by commas
        On Error GoTo ErrCatcher
        Sheets(Array("country 2019", "country 2018", "Combine")).Copy
        On Error GoTo 0

         '       Paste sheets as values
         '       Remove External Links, Hperlinks and hard-code formulas
         '       Make sure A1 is selected on all sheets
        For Each ws In ActiveWorkbook.Worksheets
            ws.Cells.Copy
            ws.[A1].PasteSpecial Paste:=xlValues
            ws.Cells.Hyperlinks.Delete
            Application.CutCopyMode = True
            Cells(1, 1).Select
            ws.Activate
        Next ws
        Cells(1, 1).Select

         '       Input box to name new file
        NewName = InputBox("Please Specify the name of your new workbook", "New Copy")

         '       Save it with the NewName and in the same directory as original
        ActiveWorkbook.SaveCopyAs ThisWorkbook.Path & "\" & NewName & ".xlsx"
        ActiveWorkbook.Close SaveChanges:=False

        .ScreenUpdating = True
    End With
    Exit Sub
ErrCatcher:
    MsgBox "Specified sheets do not exist within this workbook"
End Sub

0 个答案:

没有答案