Spock
Spock

Reputation: 61

close pop up when trying to open a multiple worksheet from a macro

I am trying to extract a some data from multiple worksheets but when I run the macro some worksheet are coming up with a Pop-up window asking me to update or don't update the link attached to the worksheet. I am looking for a way to make the macro hit "Don't update"

P.S. if possible I would like sFolder to be the root folder and also search for any "*.xlsx" contained inside C:\temp

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

Upvotes: 0

Views: 165

Answers (1)

Tim Williams
Tim Williams

Reputation: 166980

Change

With Workbooks.Open(sFolder & sFile)

To

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

More here on this topic: How to suppress Update Links warning?

Upvotes: 1

Related Questions