Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropping a sheet macro when saving to another file

Status
Not open for further replies.

hsummer

Technical User
Dec 10, 2001
13
US
when I copy a sheet to another workbook (via VBA, or course) how can i drop any VBA code imbedded in the sheet?

Specifically, I don't want a user to encounter the macro message when opening the resulting new file.

Thanks,
Harold
 
The following example should work for a sheet named Sheet1

Dim VBComp As Object
Set VBComp = Application.VBE.ActiveVBProject.VBComponents("Sheet1")
With VBComp.CodeModule
.DeleteLines 1, .countoflines
End With

A.C.
 
I haven't done this specifically, but I believe it to work. You can COPY the specific sheet to a new workbook. I have done all the code regarding the COPY sheet / save workbook but not togther (although I have thought about it too :) )
Anyways when you 'copy sheet' it doesn't copy any embedded event codes and a new workbook obviously wouldn't have any modules either.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top