Sub ETimeCard()
'
' ETimeCard Macro
' Macro created 2/23/2006 by CH
'
'You must load the Outlook Library located under Tools - References in the Visual Basic Editor
'You must Create a Folder named "C:\Temp\Time Cards\" to store the Word Doc in (see code below)
'You will get a 5 sec delay for each Email, this is done by Outlook as Spam Protection
Dim template As String
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim WordTemp As Word.Document
Set WordDoc = ActiveDocument
Dim docPath As String
Dim intTimes As Integer
Dim strLetter As String
Dim strUser As String
Dim strStatus As String
Dim docPageCount As Integer
Dim msg1 As Integer
Dim msg2 As String
Dim EMAddress As String
Dim BodyText As String
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
MaxPages = Selection.Information(wdNumberOfPagesInDocument)
For i = 1 To MaxPages
'msg1 = i
'MsgBox msg1
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=i, Name:=""
ActiveDocument.Bookmarks("\page").Select
'***********************************
Selection.Copy
Documents.Add template:= _
"C:\Documents and Settings\cherbold.CNSB\Application Data\Microsoft\Templates\Normal.dot" _
, NewTemplate:=False, DocumentType:=0
Selection.Paste
ActiveDocument.SaveAs ("C:\Temp\Time Cards\TimeCard.doc")
ActiveDocument.Close
'***********************************
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "\[*\]"
.Replacement.Text = ""
.MatchWildcards = True
.Forward = True
.Wrap = wdFindStop
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.Forward = True
End With
Selection.Find.Execute ' Replace:=wdReplaceAll
EMAddress = Mid$(Selection, 2, Len(Selection) - 2) & vbNewLine
'If Selection.Words.Count <= 10 And _
Selection.Type <> wdSelectionIP Then
'MsgBox "The selection contains " & Selection.Words.Count _
& " words."
'End If
'MsgBox EMAddress
'*****************************************************
'On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = EMAddress
.Subject = "Time Card"
'.Body = "Your text Here"
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
'ActiveDocument.FullName , Type:=olByValue, _DisplayName:="Document as attachment"
.Attachments.Add Source:="C:\Temp\Time Cards\TimeCard.doc"
.Send
End With
'**********************************************************
Next
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub