закрыть всплывающее окно при попытке открыть несколько листов из макроса - PullRequest
0 голосов
/ 28 марта 2019

Я пытаюсь извлечь некоторые данные из нескольких листов, но при запуске макроса на некоторых листах появляется всплывающее окно с просьбой обновить или не обновлять ссылку, прикрепленную к листу.Я ищу способ сделать макрос хитом "Не обновлять"

PS, если это возможно. Я бы хотел, чтобы sFolder был корневой папкой, а также выполнял поиск любого "* .xlsx", содержащегося в C: \температура

Sub tgr()

    Dim wbDest As Workbook
    Dim wsDest As Worksheet
    Dim rCopy As Range
    Dim sFolder As String
    Dim sFile As String
    Dim lRow As Long

    Set wbDest = ThisWorkbook                   'The workbook where information will be copied into
    Set wsDest = wbDest.Worksheets("Sheet1")    'The worksheet where information will be copied into
    sFolder = "C:\Path\" 'The folder path containing the xlsx files to copy from

    'would like sFolder to be the root folder and also 
    '   search for any "*.xlsx" contained inside C:\temp

    lRow = 1 'The starting row where information will be copied into

    'Adjust the folder path to ensure it ends with \
    If Right(sFolder, 1) <> "\" Then sFolder = sFolder & "\"

    'Get the first .xlsx file in the folder path
    sFile = Dir(sFolder & "*.xlsx")

    'Begin loop through each file in the folder
    Do While Len(sFile) > 0

        'Open the current workbook in the folder
        With Workbooks.Open(sFolder & sFile)
            'Copy over the formulas from A1:C3 from only the first 
            '   worksheet into the destination worksheet
            Set rCopy = .Sheets(1).Range("C9:D26")
            wsDest.Cells(lRow, "A").Resize(rCopy.Rows.Count, rCopy.Columns.Count).Formula = rCopy.Formula

            'Advance the destination row by the number of rows being copied over
            lRow = lRow + rCopy.Rows.Count

            .Close False    'Close the workbook that was opened from the folder without saving changes
        End With
        sFile = Dir 'Advance to the next file
    Loop

End Sub

1 Ответ

1 голос
/ 28 марта 2019

Изменить

With Workbooks.Open(sFolder & sFile)

На

With Workbooks.Open(sFolder & sFile, UpdateLinks:=False)

Подробнее здесь по этой теме: Как подавить предупреждение об обновлении ссылок?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...