ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Once-only Macro (https://www.excelbanter.com/excel-programming/327567-once-only-macro.html)

Libby

Once-only Macro
 
Hi

I have a template .xlt with code in (or a macro called from) the workbook
open event to format various cells.
The template is then saved as a .xls
How can I removed the workbook open event code when the .xlt is saved as .xls

Thanks
Libby

Bob Phillips[_6_]

Once-only Macro
 
Hi Libby,

Add this code to the template.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim vbMod As Object

Set vbMod = ThisWorkbook.VBProject.VBComponents("THisWorkbook" )
With vbMod.CodeModule
.DeleteLines 1, .CountOfLines
End With

End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


But I have to ask. why not format the cells in the template, and do away
with the event code?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Libby" wrote in message
...
Hi

I have a template .xlt with code in (or a macro called from) the workbook
open event to format various cells.
The template is then saved as a .xls
How can I removed the workbook open event code when the .xlt is saved as

..xls

Thanks
Libby




Tushar Mehta

Once-only Macro
 
Why not format the cells before saving the template file? That way
there is no need for any code!

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Hi

I have a template .xlt with code in (or a macro called from) the workbook
open event to format various cells.
The template is then saved as a .xls
How can I removed the workbook open event code when the .xlt is saved as .xls

Thanks
Libby



All times are GMT +1. The time now is 02:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com