icepirates1234
MIS
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
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