Hello everyone: I’ve been in IT forever but I just recently started using VBA for MS Word and I am having just a bit of trouble and I would be delighted if you could help. I have a VBS script that quires Active Directory for computers that have not been used in 21 days or more. Normally this file is under 100 lines but the exact number of Non-Reporting Computers varies each day. The Visual Basic Script writes the Output to a TXT file. Every day I need to copy the output file into a Outlook document (MS Word) and email it to about 5 or 6 people. I have been running short Macros to remove lines with “Retired” in them and to move Lines with the word “ACE” to the top of the list but that is taking longer to do each day and I feel like I should automate the process..
Output from the VBS text file looks like the following example.
Sample of Non-Reporting Computers for August 31, 2012
# DATE SN Days Note
1 JULY 7 2012 2ua8144d21 21 ace3
2 JUNE 30 2012 CMD1234TRE 22 New Town
3 JUNE 30 2012 CMD1234TRE 24 New Town
4 JULY 8 2012 234ABCDx21 22 ACE3
Sorry the document has these items arranged on columns but I'm unable to reproduce it here
The code I have so far follows this but it does not exit at EOF and produces an endless loop. The second problem is I would like to use a Variable to call additional subs without having the repeat the Do Loop (everything I have tried so far will not compile) and maybe using a variable to call a Sub routines is forbidden .
Perhaps I am just getting old or maybe I am blind but I don’t know why the loop is not ending at End of Document. Any help will be greatly appreciated.
Sub LoopThroughDoc () ‘loops through until EOF
Selection.HomeKey Unit:=wdStory
Selection.HomeKey Unit:=wdLine
Do Until ActiveDocument.Bookmarks("\Sel").Range.End = _
ActiveDocument.Bookmarks("\EndOfDoc").Range.End
Selection.MoveDown
RemoveRetire ‘ go Sub - I would like to use a variable here to call outer Subs something like SubVariable = RemoveRetire Or MoveACE
Loop
MsgBox ("the end of the document")
End Sub
___________________________________________________________________________
Sub RemoveRetire() ‘ Sub to Remove the line with “Retired” in it
Selection.Find.ClearFormatting
With Selection.Find
.Text = "retired"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
_______________________________________________________________________
Output from the VBS text file looks like the following example.
Sample of Non-Reporting Computers for August 31, 2012
# DATE SN Days Note
1 JULY 7 2012 2ua8144d21 21 ace3
2 JUNE 30 2012 CMD1234TRE 22 New Town
3 JUNE 30 2012 CMD1234TRE 24 New Town
4 JULY 8 2012 234ABCDx21 22 ACE3
Sorry the document has these items arranged on columns but I'm unable to reproduce it here
The code I have so far follows this but it does not exit at EOF and produces an endless loop. The second problem is I would like to use a Variable to call additional subs without having the repeat the Do Loop (everything I have tried so far will not compile) and maybe using a variable to call a Sub routines is forbidden .
Perhaps I am just getting old or maybe I am blind but I don’t know why the loop is not ending at End of Document. Any help will be greatly appreciated.
Sub LoopThroughDoc () ‘loops through until EOF
Selection.HomeKey Unit:=wdStory
Selection.HomeKey Unit:=wdLine
Do Until ActiveDocument.Bookmarks("\Sel").Range.End = _
ActiveDocument.Bookmarks("\EndOfDoc").Range.End
Selection.MoveDown
RemoveRetire ‘ go Sub - I would like to use a variable here to call outer Subs something like SubVariable = RemoveRetire Or MoveACE
Loop
MsgBox ("the end of the document")
End Sub
___________________________________________________________________________
Sub RemoveRetire() ‘ Sub to Remove the line with “Retired” in it
Selection.Find.ClearFormatting
With Selection.Find
.Text = "retired"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
_______________________________________________________________________