0% found this document useful (0 votes)
62 views4 pages

Sample Set Macros

This document contains 4 VBA macros that perform various tasks in Microsoft Word documents: 1. The SCForm macro selects the whole story of the active document, sets the language to US English, checks spelling, and protects the document allowing only form fields. 2. The FindMultiItemsInDoc macro finds and highlights multiple items from a reference document in the active document. 3. The Macro9 macro permanently enables editing, saves the active document with settings, and closes the active window and application. 4. The Macro300 macro formats tables to allow page breaks, deletes comments, accepts all changes, turns off grammar/spelling checks, saves and closes the active document. The Macro302 macro loops

Uploaded by

cdd cc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views4 pages

Sample Set Macros

This document contains 4 VBA macros that perform various tasks in Microsoft Word documents: 1. The SCForm macro selects the whole story of the active document, sets the language to US English, checks spelling, and protects the document allowing only form fields. 2. The FindMultiItemsInDoc macro finds and highlights multiple items from a reference document in the active document. 3. The Macro9 macro permanently enables editing, saves the active document with settings, and closes the active window and application. 4. The Macro300 macro formats tables to allow page breaks, deletes comments, accepts all changes, turns off grammar/spelling checks, saves and closes the active document. The Macro302 macro loops

Uploaded by

cdd cc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Sub SCForm()

ActiveDocument.Select
Selection.WholeStory
Selection.LanguageID = wdEnglishUS
ActiveDocument.CheckSpelling
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
Sub FindMultiItemsInDoc()
Dim objListDoc As Document
Dim objTargetDoc As Document
Dim objParaRange As Range, objFoundRange As Range
Dim objParagraph As Paragraph

Set objTargetDoc = ActiveDocument


Set objListDoc = Documents.Open(FileName:="D:\References.docx")
objTargetDoc.Activate

For Each objParagraph In objListDoc.Paragraphs


Set objParaRange = objParagraph.Range
objParaRange.End = objParaRange.End - 1

With Selection
.HomeKey Unit:=wdStory

' Find target items.


With Selection.Find
.ClearFormatting
.Text = objParaRange
.MatchWholeWord = True
.MatchCase = False
.Execute
End With

' Highlight the found items.


Do While .Find.Found
Set objFoundRange = Selection.Range
objFoundRange.HighlightColorIndex = wdBrightGreen
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Next objParagraph
End Sub

Sub Macro9()
'
' Macro9 Macro
' enable editing permanently
'
ChangeFileOpenDirectory "D:\"
ActiveDocument.SaveAs2 FileName:="Test.doc", FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, CompatibilityMode:=0
ActiveWindow.Close
Application.Quit
End Sub

Sub Macro300()
'
' Macro300 Macro
' delete comments, accept all changes, correct grammar, and save
'

Dim tbl As Table


For Each tbl In ActiveDocument.Tables
tbl.Rows.AllowBreakAcrossPages = True
Next

Dim n As Long
Dim oComments As Comments
Set oComments = ActiveDocument.Comments
For n = oComments.Count To 1 Step -1
oComments(n).Delete
Next 'n
Set oComments = Nothing

ActiveDocument.PageSetup.Orientation = wdOrientLandscape
ActiveDocument.ShowGrammaticalErrors = False
ActiveDocument.ShowSpellingErrors = False
ActiveDocument.Range.NoProofing = True
ActiveDocument.AcceptAllRevisions
ActiveDocument.TrackRevisions = False
ActiveDocument.Save
ActiveWindow.Close
End Sub
Sub Macro302()
'
' Macro302 Macro
' finale
'

Dim file
Dim path As String

path = "C:\Users\nnadkarni\Desktop\PayGate\"

file = Dir(path & "*.docx")

Do While file <> ""


Documents.Open FileName:=path & file
Application.Run MacroName:="Macronew"

file = Dir()
Loop
End Sub

You might also like