Excel VBA problem with copying workbook to another workbook - application freezes when copying to certain files

I have a problem that honestly puts me at a loss.

I copy a set of books in the book "master" (copying all the sheets). There are two methods that I can use, either by looking at each sheet in books to copy everything into the wizard, or copy the book as a whole and put it in the main book. I use the second method, using an array to remove sheets that I don't need.

Dim ws() As String ' declare string array
ReDim ws(wb.Worksheets.Count) As String ' set size dynamically
Dim counter As Long ' running counter for ws array
counter = 0
For c = 1 to WS_Count
If wb.Worksheets(c).Name <> "TEST" Then
    ws(counter) = wb.Worksheets(c).Name
    counter = counter + 1
End If
Next

ReDim Preserve ws(counter-1) As String wb.Worksheets(ws).Copy Before:=master.Worksheets(master.Worksheets.Count)

Both approaches that I tried to work with some files, however:

1) The first approach is problematic because it leaves a link to the source file, so I switched to approach 2, which bypasses this problem, since the link is not supported.

2) 2 . , , , , 50 , , . ( , 1, 1 - )

, ( ), wb.Worksheets(ws).Copy Before:=master.Worksheets(master.Worksheets.Count)

- , ? - ? , , 26 , 896 . , , 164 , 164 . Office Professional Plus 2010.

, , , , , .

- ?

+4
1

"", -1?

For c = WS_Count to 1 

    If wb.Worksheets(c).Name <> "TEST" Then
        ws(counter) = wb.Worksheets(c).Name
        counter = counter - 1
    End If
Next c
0

Source: https://habr.com/ru/post/1545518/


All Articles