-
Hi, All,
Well, to help all y'all help me, I recorded a macro and then annotated it so you can see the process that I'm trying to automate.
[vba]Sub Macro5()
'
' Macro5 Macro
'
'
ChangeFileOpenDirectory _
"C:\Documents and Settings\mckenzier\Desktop\Inquiry Support\G5\U07\"
Documents.Open FileName:="G5U07_InquirySupport.doc", ConfirmConversions:= _
True, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
ActiveWindow.ActivePane.View.Zoom.Percentage = 100
' The first lesson is a "C", so, I page down until I find the 2nd instance of
' My Notes. In wdVBA how do I read the first line and test the 8th character
' to see if it's a C or an I?
Selection.MoveDown Unit:=wdScreen, Count:=15, Extend:=wdExtend
Selection.Copy
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
' I go back to the top to get the first line
Selection.HomeKey Unit:=wdStory
' There is a caption that I don't need ( LO name: ) so I highlight and delete it.
Selection.MoveRight Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
' Then I highlight and cut the portion I need for the filename.
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Cut
' Since there are two activities, I next page down to the next instance of the
' name and delete it.
Selection.MoveDown Unit:=wdScreen, Count:=9
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
' The name I cut I now paste into the File Save dialog and select RTF for the
' file type.
ActiveDocument.SaveAs FileName:= _
"G5 EC 00216 Activity Title 1 G5 U7 L1.rtf", FileFormat:=wdFormatRTF, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
' I close the new document and proceed to repeat the process; in this case, the
' 2nd lesson is also a "C" type, so, it will look very much like the above.
ActiveDocument.Close
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdScreen, Count:=11, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveUp Unit:=wdParagraph, Count:=2
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Cut
Selection.MoveDown Unit:=wdScreen, Count:=6
Selection.EndKey Unit:=wdLine
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.SaveAs FileName:= _
"G5 EC 00217 Activity Title 2 G5 U7 L2.rtf", FileFormat:= _
wdFormatRTF, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
ActiveDocument.Close
' The 3rd Lesson is an "I" so there is only one activity to process; note that this
' is also the last activity in the file. In VBA, how do I detect the EOF and close
' things gracefully?
Selection.MoveDown Unit:=wdScreen, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdScreen, Count:=6, Extend:=wdExtend
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
Selection.HomeKey Unit:=wdStory
Windows("G5U07_InquirySupport.doc [Compatibility Mode]").Activate
Selection.HomeKey Unit:=wdStory
Windows("Document13 [Compatibility Mode]").Activate
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Cut
ActiveDocument.SaveAs FileName:="G5_EI_00218_Activity Title 3 G5 U7 L3.rtf", _
FileFormat:=wdFormatRTF, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.Save
ActiveDocument.Close
ActiveDocument.Close
End Sub
[/vba]
I'm somewhat adept in Excel VBA but this is my first venture into the jungle of Word VBA.
Thanks,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules