Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi everyone,
Programming in Excel is rather new to me. Ive been able to get by thus far by recording macros and looking at the code. I have been able to manipulate the code by referring to the VBE help and these news groups. Im looking for assistance in modifying my code such that when the file is saved (SAVE AS actually), all code is removed from the new file but not the current file. Ive searched these discussions groups and found a reference to http://www.cpearson.com/excel/VBE.aspx where the following code will delete all VBA in a project. Sub DeleteAllVBACode() Dim VBProj As VBIDE.VBProject Dim VBComp As VBIDE.VBComponent Dim CodeMod As VBIDE.CodeModule Set VBProj = ActiveWorkbook.VBProject For Each VBComp In VBProj.VBComponents If VBComp.Type = vbext_ct_Document Then Set CodeMod = VBComp.CodeModule With CodeMod .DeleteLines 1, .CountOfLines End With Else VBProj.VBComponents.Remove VBComp End If Next VBComp End Sub What I am not clear on is whether or not this code will delete all code in the workbook that is currently open or whether it will delete the code in the new workbook that is created when my code does a save as. The first line under the declarations makes me think perhaps it deletes the code in the workbook currently opened. Am I correct? FWIW, Im including the code that executes when my user clicks the command button to save the file. Sorry in advance if the lines don't wrap properly. Private Sub SaveData_Click() If Trim(Worksheets("Post-Service").Range("D3").Value = "") Then MsgBox ("You must enter a serial number.") Exit Sub Else Worksheets("Post-Service").Range("D3") = UCase(Worksheets("Post-Service").Range("D3")) If Left(Worksheets("Post-Service").Range("D3"), 1) = "C" Then ActiveWorkbook.SaveCopyAs "\\MyPath\" & "SR50_SN_" & Range("d3") & "_" & Format(Now, "yyyymmmdd") & ".xls" Else If MsgBox("Are you sure the serial number doesn't begin with C?", vbYesNo) = vbYes Then ActiveWorkbook.SaveCopyAs "\\MyPath\" & "SR50_SN_" & Range("d3") & "_" & Format(Now, "yyyymmmdd") & ".xls" Else MsgBox ("Please fix the serial number.") End If End If End If End Sub Thanks for any and all assistance. Chris |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel creating TMP with each save but not deleting on close | Excel Discussion (Misc queries) | |||
Creating a path to save a file | Excel Programming | |||
Can VBA save file after deleting all VB code? | Excel Programming | |||
Problem: vba code for creating a button to save worksheet as Cell | Excel Programming | |||
Deleting code in a file with code.. | Excel Programming |