How to insert code into a workbook from another workbook

Frenzyy

New Member
Joined
May 26, 2019
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi All, not sure if this is even possible but I'm trying to save a file from another workbook and then ensure that nobody can update any links in it, etc. upon opening, and so I'd need to insert the below two lines of code under 'Workbook_Open' but I'm unsure how to this, so I'd greatly appreciate some help.
VBA Code:
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False

This is my save as line:
VBA Code:
 wb2.SaveAs fileName:=filePath & "\" & fileName & ".xlsm", ReadOnlyRecommended:=True

Many thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Open both workbooks and In the VBA Screen on the left you should see a list of workbooks and sheet names and any modules you have. Just below the last sheet name for the book you want the code in it will show you ThisWorkBook. Double click this and it will then give you two drop downs at the top change the left one from General to Workbook this will then give you the On_Open Event and paste your code above End Sub.
 
Upvote 0
Hi Trevor, sorry if I wasn't clear enough with my question but I'm looking to do it using the code within the already activeworkbook, if you know what I mean. As you can see above, I'm saving the newly created workbook so that it later opens as read-only. Now I want to add what I mentioned above as well but just unsure how.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,617
Latest member
Narendra Babu D

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