Once-only Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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)
 
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
 
Back
Top