Apply Macro to a specific Workbook

Keibri

New Member
Joined
May 29, 2015
Messages
8
Hi all,

I have the following basic macro:


<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit;">
Sub RemoveDuplicates()
Cells.RemoveDuplicates Columns:=Array(1)
End Sub
</code>
basically it's a simple macro which removes duplicates.

I would like to edit this macro so as when it is run it will be applied on a particular workbook, say "Workbook 1". However "Workbook 1" is not the active workbook. Rather, it is another workbook, which when the macro is run it will be closed.

The macro should remove the duplicates of "Workbook 1", even though "Workbook 1" is closed (not active).

I had posted the original query in another forum but would really appreciate if someone can guide me further. Kindly find original post in the link below:
Apply Macro to a specific Workbook



Can someone help me out
smile.gif
?

Appreciate it a lot

Thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
The macro can be expanded to open workbook 1, remove duplicates, save workbook 1 and then close it. Is that what you want?
 
Upvote 0
That's something new for me. Never knew this simply function existed. Now to figure out how it's working exactly.
 
Upvote 0
Yeah, I think I managed to find a way around it, just like JoeMo indicated:

Code:
[/FONT][/COLOR]Sub RemoveDuplicates()


    Workbooks.Open "C:\Users\User\Documents\Workbook 1.xlsm"
    
    Workbooks("Workbook 1").Sheets("Sheet1").Cells.RemoveDuplicates Columns:=Array(1)
    
    ActiveWorkbook.Save
    Workbooks("Workbook 1.xlsm").Close
End Sub


Thanks a lot for your idea :)!!!

Cheers :)
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

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