Once-only Macro

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
 
B

Bob Phillips

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)
 
T

Tushar Mehta

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top