mergeworkbook method - vba

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I am trying to merge 2 different files. The first file is hello1.xlsm (workbook1) in which i wrote the vba code below. hello1.xlsm is saved in the same folder of the second file which I want to merge it with, the second file called abc.xlsx. I got run time error - "method "mergeworkbook' of object _workbook failed". Any help would be very much appreciated.

Code:
Sub workbookmerge()
    Workbooks(1).MergeWorkbook "abc.xlsx"
End Sub

I followed this article

https://docs.microsoft.com/en-us/office/vba/api/excel.workbook.mergeworkbook
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Follow the steps to number 6, then run the macro.

https://support.office.com/en-us/ar...workbook-aa7c3598-5ad7-4fea-8c00-2daa7a934239



It also does the following:

- The book with the macro and the copy must be shared
- The book with the copy must be closed and in the same folder as the original book

Code:
Sub merge_book()
    'thisworkbook name is hello1.xlsm
    ruta = ThisWorkbook.Path & "\"
    ThisWorkbook.MergeWorkbook ruta & "hello2.xlsm"
End Sub

Regards Dante Amor

****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">follow the steps to number 6, then run your macro</body>
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top