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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Macro's

Status
Not open for further replies.
Feb 17, 2009
10
CA
Hello,

I have a Macro that runs, and saves a document with whatever today's date is...The next step is when a user closes the Word application by clicking on the Red-X, I need all the VBA/(Macros) to delete from the visual basic editor.

What would be a code to do that? Here is my current code if its of use to anyone:

Sub AutoOpen()
Dim myWB As Excel.Workbook
Dim TempStr As String
Dim intRows As Integer
Dim intRecords As Integer
Dim intProjects As Integer
Dim intCount As Integer

Dim strEmployee(0 To 1000) As String

Set myWB = GetObject("X:\2009 Core Projects.xls")
Selection.GoTo What:=wdGoToBookmark, Name:="first_mark"
TempStr = "Start"
intRows = 3
'Get all projects
Do While TempStr <> ""
intRows = intRows + 1
TempStr = myWB.Sheets("Sheet1").Cells(intRows, 3)
Loop
intRows = intRows - 1
intProjects = intRows
'Get all employees
For intRecords = 3 To intRows
If (myWB.Sheets("Sheet1").Cells(intRecords, 9) = "Not Started" Or myWB.Sheets("Sheet1").Cells(intRecords, 3) = "") Then
Else
strEmployee(intRecords) = myWB.Sheets("Sheet1").Cells(intRecords, 5)
End If
Next

'List employees and projects in Word Document
For intRecords = 3 To intRows
If strEmployee(intRecords) <> "" Then
'Has this employee already been entered into the Word Report?
For intCount = 3 To intRecords - 1
'Already in Word Report - Move to next employee
If strEmployee(intRecords) = strEmployee(intCount) Then GoTo Reported
Next
'Not In Word Report - Include in Document
Selection.TypeText strEmployee(intRecords)

'Bold Names
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.EndKey Unit:=wdLine
Selection.TypeText vbCr
Selection.Font.Bold = wdToggle

For intCols = 1 To intProjects
If myWB.Sheets("Sheet1").Cells(intCols, 5) = strEmployee(intRecords) Then
If myWB.Sheets("Sheet1").Cells(intCols, 9) <> "Not Started" Then
Selection.TypeText myWB.Sheets("Sheet1").Cells(intCols, 3) & vbCr
End If
End If
Next
'Spacer to next employee
Selection.TypeText vbCr
Reported:
End If
Next

Set myWB = Nothing

End Sub

Private Sub CommandButton1_Click()
Dim Today, FolderName$, DateValue$, NameofFile$, FullFileName$
FolderName$ = "X:\Weekly Meetings\"
DateValue$ = Format(Now, "yyyy-mm-dd")
NameofFile$ = "- Core Agenda"
FullFileName$ = FolderName$ + DateValue$ + " " + NameofFile$
ActiveDocument.SaveAs FileName:=FullFileName$, FileFormat:=wdFormatDocument
End Sub
 
Why do you have the code in the document file at all? If the code was in a global template (essentially a code container) then you could execute your procedures and the user would never see the code. Even if they got into the VBE the global template would be "Project unviewable".

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top