Documentos de Académico
Documentos de Profesional
Documentos de Cultura
MACRO 1
AddText text
Cancel = (MsgBox(text, vbOKCancel, "Event") = vbCancel)
End Sub
MACRO 2
Sub TestGlowAndReflection()
With ActiveDocument.Range
.Font.Size = 24
.Font.Bold = True
.Font.Name = "Gabriola"
Dim i As Integer
' Note a few things:
' * The values of the StylisticSet enumerated values
' are powers of two. You can also use the wdStylisticSet01 and
' so on values to set individual stylistic sets.
' * Few fonts provide different stylistic sets. Gabriola provides just
' a few different sets, although you can still request all 20.
' * Fonts can have up to 20 stylistic sets, changing subtle features
' of the font.
For i = 1 To 20
.InsertAfter i & ": ABCDEFGHIJKLMNOPQRSTUVWXYZ"
.InsertParagraphAfter
.Paragraphs(i).Range.Font.StylisticSet = 2 ^ (i - 1)
Next i
.InsertParagraphBefore
.InsertBefore "Here is some text."
End With
With ActiveDocument.Range.Paragraphs(1).Range
With .Font
.Size = 24
.ColorIndex = wdRed
' Work with the Font.Glow property:
With .Glow
' Can also set the Color.RGB property:
.Color.ObjectThemeColor = wdThemeColorAccent1
.Radius = 10
.Transparency = 0.8
End With
With .Reflection
.Offset = 2.4
.Blur = 0.5
.Size = 100
.Transparency = 0.5
' You can also set the Type property, which
' includes settings for the preset Reflection
' types:
' .Type = msoReflectionType1
End With
End With
End With
End Sub
MACRO 3
Sub CropDemo()
' Put your own image path in here. This image path
' should work for standard Windows 7 installations.
Const fileName As String = "C:\Windows\Web\Wallpaper\Landscapes\img10.jpg"
With ActiveDocument
Dim shp As Shape
Set shp = ActiveDocument.Shapes.AddPicture(fileName, msoFalse, msoTrue)
shp.Line.Visible = True
With shp.PictureFormat.Crop
' Modify the picture itself, not its container:
' Shift the picture 10% to the right and down,
' and then make the picture 90% of its original size.
.PictureOffsetX = picWidth / 10
.PictureOffsetY = picHeight / 10
.PictureHeight = picHeight * 0.9
.PictureWidth = picWidth * 0.9
' Now modify the cropping by changing the shape
' of the container. Changing the shape alters
' the portion of the picture that you see:
.ShapeHeight = 100
.ShapeWidth = 100
.ShapeLeft = 100
.ShapeTop = 150
End With
End With
End Sub
MACRO 4
Sub TestQuickStyles()
' Word 2010 adds the ability to apply a quick style set. Previously
' you could only save a quick style set.
MACRO 5
Sub DemoThemeAndQuickStyle()
' Modify this path for your own installation of Microsoft Office:
Const themeFolder As String = "C:\Program Files (x86)\Microsoft Office\Docume
nt Themes 14\"
' Single step through this code to see the changes as they occur.
' Look at the list of Quick Styles in the user interface
' for more quick style names:
ActiveDocument.ApplyQuickStyleSet "Distinctive"
ActiveDocument.ApplyQuickStyleSet "Elegant"
ActiveDocument.ApplyQuickStyleSet "Manuscript"
MACRO 6
ub TestCheckInWithVersion()
ActiveDocument.Content.InsertAfter "Here is a change!"
MACRO 7
Sub SelectionClearFormattingDemo()
' Apply character and paragraph formats.
' Press F8 to step into this the first time.
' Press Shift+F8 to step over subsequent lines of code:
ApplyFormattingAndSelect Sentences(3)
End Sub
MACRO 8
Sub DemoCompareDocuments()
' Save the current document, including this code.
Const path1 As String = "C:\Temp\Doc1.docm"
Const path2 As String = "C:\Temp\Doc2.docm"
Const path3 As String = "C:\Temp\Doc3.docm"
' Save with macros enabled, because this code exists within
' the document you're saving. If the document didn't contain
' code, you would not need to specify the file format.
Set doc1 = ActiveDocument
doc1.SaveAs path1, wdFormatXMLDocumentMacroEnabled
End Sub
MACRO 9
Sub DemoSaveAsQuickStyleSet()
' Given the five paragraphs you added (by following the instructions),
' modify the color, font, and paragraph layout. Then save the whole
' thing as a new quick style.
' Modify this path for your own installation of Microsoft Office:
Const themeFolder As String = "C:\Program Files (x86)\Microsoft Office\Docume
nt Themes 14\"
' Modify the name of the new template to meet your needs:
Const newTemplateName = "C:\temp\Demo1.dotx"
' Save the settings as a new quick style set. This actually
' creates a new document template, which you can use for
' creating future documents.
ActiveDocument.SaveAsQuickStyleSet newTemplateName
' Verify that in the new document that this statement creates,
' the theme color and font correspond to the options you
' set when you created the quick set.
Documents.Add newTemplateName
End Sub
MACRO 10
Sub RangeExportImportFragments()
' Word 2007 and later allows you to export ranges of text as a fragments.
' You can them reimport these fragments and use them in any document.
' Given the sample document with 5 paragraphs, try exporting a fragment,
' then modifying the format and reimporting the fragment to see the behavior.
' Take a moment and load the fragment file into Microsoft Word.
' It should load like any other document.
' Although the second paramter indicates style behavior for the incoming
' fragment, it doesn't appear to make any different which option
' you choose. Both True and False give the same result. If False, the
' fragment should use the formatting from the original document, not the
' current document, but this doesn't appear to be the case. The ImportFragmen
t
' method uses the formatting from the source document, no matter how this
' parameter has been set:
Words(1).ImportFragment FRAGMENT_FILE, False
Words(100).ImportFragment FRAGMENT_FILE, True
End Sub