将工作表加载到工作簿时如何隐藏单元格引用

时间:2018-11-23 14:28:38

标签: excel vba excel-vba

将工作表从另一个工作簿导入到新工作簿时,如何隐藏以下消息。

enter image description here

如何完全跳过这些?我不想更改任何引用。

这是我的代码:

Sub Import()

Dim masterWB As Workbook
Dim dailyWB As Workbook

Application.DisplayAlerts = False

'Set Current Workbook as Master
Set masterWB = Application.ThisWorkbook
'Set some Workbook as the one you are copying from
Set dailyWB = Workbooks.Open("file name")

Application.DisplayAlerts = True

'Copy the Range from DailyWB and Paste it into the MasterWB
dailyWB.Sheets("Summary").Range("A1:F200").Copy masterWB.Sheets("TEST").Range("A1").Rows("1:1")
Columns("A:F").Select
Selection.Columns.AutoFit

'Close the Workbook without saving
dailyWB.Close False
'Clear the Variables
Set dailyWB = Nothing
Set masterWB = Nothing

End Sub

1 个答案:

答案 0 :(得分:1)

我认为复制到另一个工作簿后,您必须移动Application.DisplayAlerts = True

Sub Import()

    Dim masterWB As Workbook
    Dim dailyWB As Workbook

    Application.DisplayAlerts = False

    'Set Current Workbook as Master
    Set masterWB = Application.ThisWorkbook
    'Set some Workbook as the one you are copying from
    Set dailyWB = Workbooks.Open("file name")


    'Copy the Range from DailyWB and Paste it into the MasterWB
    dailyWB.Sheets("Summary").Range("A1:F200").Copy masterWB.Sheets("TEST").Range("A1").Rows("1:1")
    Columns("A:F").Select
    Selection.Columns.AutoFit

    Application.DisplayAlerts = True

    'Close the Workbook without saving
    dailyWB.Close False
    'Clear the Variables
    Set dailyWB = Nothing
    Set masterWB = Nothing

    End Sub