Merge wbs to Master wb - Control the startup message about updating linked workbooks and copy only values not formulas

Adam Elsheimer
Adam Elsheimer used Ask the Experts™
on
I have to copy data wbs to a master wb. The simple macro below works fine.

Q1: First, in the Data wbs there are  links to another wbs. I don't know how to control the startup message about updating linked workbooks in Excel when I run the macro. I have changed the Excel Options to avoid the message but  no better result. How can I change the macro that it copies from closed data wbs?

Q2:  Second, I would like copy only the values, no formulars to the master wb.
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial


Sub simpleXlsMerger()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
 
'change folder path of excel files here
Set dirObj = mergeObj.Getfolder("C:\Users\Adam\Desktop\Verbundaktion\")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
 
Range("A3:IV" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
 
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
bookList.Close
Next
End Sub

Open in new window


Thank you.

Regards,

Adam

Source
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ShumsManaging Director/Excel VBA Developer
Distinguished Expert 2018

Commented:
Hi Adam,

Please try below:
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim LR As Long
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
 
'change folder path of excel files here
Set dirObj = mergeObj.Getfolder("C:\Users\Adam\Desktop\Verbundaktion\")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Set bookList = Workbooks.Open(everyObj)
Application.AskToUpdateLinks = True
Application.DisplayAlerts = True

Range("A3:IV" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
LR = Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
Worksheets(1).Range("A" & LR + 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
bookList.Close
Next
End Sub

Open in new window

Author

Commented:
Shums, many thanks for your uncomplicated help.

Update Message and paste works fine.  I get know the save messagebox. I am so sorry to forget to mention this in my description.

Unbenannt.JPG
Regards,

Adam
Managing Director/Excel VBA Developer
Distinguished Expert 2018
Commented:
no problem, try below:
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim LR As Long
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
 
'change folder path of excel files here
Set dirObj = mergeObj.Getfolder("C:\Users\Adam\Desktop\Verbundaktion\")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Set bookList = Workbooks.Open(everyObj)
Application.AskToUpdateLinks = True
Application.DisplayAlerts = True

Range("A3:IV" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
LR = Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
Worksheets(1).Range("A" & LR + 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.DisplayAlerts = False
bookList.Close
Application.DisplayAlerts = True
Next
End Sub

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Sorry, one issue more.

Q: Can the macro overwrite the existing values please. When I update the Master file I get Duplicates.

Unbenannt.JPG
Thanks

Regards,

Adam
ShumsManaging Director/Excel VBA Developer
Distinguished Expert 2018

Commented:
Sorry Adam this is different issue, I need to write new code.

Author

Commented:
Shums, many thanks for your very fast and uncomplicated help.

Regards,

Adam
ShumsManaging Director/Excel VBA Developer
Distinguished Expert 2018

Commented:
You're Welcome Adam! Please to help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial