Introduction to the features of this word's VBA code: Add a custom command to the middle of the right-click Text menu (the menu that appears when you right-click the text), and perform the appropriate procedure.
Private Sub Document_Close ()
On Error Resume Next
Application.CommandBars ("Text"). Controls ("Test"). Delete ' Restore original menu
End Sub
Private Sub Document_Open ()
Dim Half as Byte
On Error Resume Next
Dim Newbutton as CommandB
The VBA code sets the Word table properties.
Dim I as Table, N as Integer
On error Resume Next ' Ignore error
application.screenupdating = False ' Turn off screen update
For all I in activedocument.tables ' loops in the table
With I
. style = List Type 4 ' Sets all tables to list Type 4 '
With. Borders ' border
. InsideLineStyle = wdLineStyleSingle ' Set internal border line
End With
With. Rows (1
Using VB, you can set the font of the outside of the table to the actual operation as follows:The VB code is as follows:Suboliver_1 () Selection.endkey Unit:=wdstory'cursor moves to the end of the text fori =1 toActiveDocument.Tables.Count'There are several tables, the following operations are looped several times withApplication.browser. Target= Wdbrowsetable'the insertion point is in the table. Previous'before the insertion point moves to the previous table End withselection.moveup
*. MatchAllWordForms =False $ End withPanax NotoginsengSelection.Find.ExecuteReplace:=wdReplaceAll - 'above is the recorded macro theACTIVEDOCUMENT.SAVEAS2 FILENAME:=FP "\" X ". docx" + Activewindow.close A Next theApplication.ScreenUpdating =True + End Sub - Subfolder browser () $ SetObmapp =CreateObject("shell.application"). BrowseForFolder (0,"Please select a file directory:",0,0) $ If notObmapp is Nothing Then -fp = Obmapp. Self.path "" - Else the Exit Sub -
Every four pictures on one page , the first row is the file name of four pictures
Insert Picture Resize Reference
Sub final () Dim FN as String, N%, w#, h#, pw#, Ph#with activedocument.pagesetup ' Set the paper type and margins (A4, margin 2cm) and calculate the width of the image. Orientation = wdorientportrait. TopMargin = centimeterstopoints (2). BottomMargin = centimeterstopoints (2). LeftMargin = centimeterstopoints (2). RightMargin = centimeterstopoints (2). Gutter = centimet
The following wapp is a predefined Word document engineering variable.
The following code is for pages with VBA code page margins, paper portrait, Alignment, Header page static, and so on.
WApp.ActiveDocument.PageSetup.LineNumbering.Active =0;//Line number
WApp.ActiveDocument.PageSetup.Orientation =microsoft.office.interop.word.wdorientation.wdorientportrait;//page orientation
WApp.ActiveDocument.PageSe
The following code sets the various formats for Word fonts through VBA code.
WApp.Selection.Font.NameFarEast = "XXFarEastFont-Arial";
WApp.Selection.Font.NameAscii = "Times New Roman";
WApp.Selection.Font.NameOther = "Times New Roman";
WApp.Selection.Font.Name = "Song Body";
WApp.Selection.Font.Size = float. Parse ("14");
WApp.Selection.Font.Bold = 0;
WApp.Selection.Font.Italic = 0;
WApp.Selection.F
The following wapp is a predefined Word document engineering variable.
The following code modifies word paragraph indents, paragraph spacing, line spacing, paging, and so on through VBA code.
Paragraph format setting
WApp.Selection.ParagraphFormat.LeftIndent = wapp.centimeterstopoints (float. Parse ("0"))//left Indent
WApp.Selection.ParagraphFormat.RightInden
SUBNBSP;GENEQ () ifselection.startThis article is from the "GONE with the Wind" blog, please be sure to keep this source http://h2appy.blog.51cto.com/609721/1604040Considerations when you use VBA to automatically generate formulas in Word
The function of the following code is to select the current page of the Word document, and note that it is the current page, the page where the insertion bar is located, not the full text.
Dim Currentpagestart as Long, currentpageend as Long, myRange as Range
Dim currentpage As Integer, Pages as Integer
On Error Resume Next
CurrentPage = Selection.Information (wdActiveEndPageNumber)
Pages = Selection.Information (wdnumberofpagesindocument)
Curre
Enter the corresponding vowel plus tone, and then use VBA to unify the replacement, which is much faster.
such as: She1ng dia4o
When selected, run the following macro to get:
Shēng Diào
It is especially useful for pinyin to be entered in the primary language class at times. Consider putting the macro in the corresponding template.
The VBA code is as follows:
Dim Findarr, Replacearr
Dim I as Long
app
The following VBA code functionality, step one, adds text dzwebs text to the top of Word's current document. Then, set the first paragraph to center, and then add a half inch spacing after the paragraph. The Dzwebs format is set to 36 points, the Arial font.
Dim Rngformat as Range
Set Rngformat = ActiveDocument.Range (start:=0, end:=0)
With Rngformat
. InsertAfter text:= "Dzwebs"
. InsertParagraphAfter
With. Font
. Name = "Official script"
. S
Public sub duqu () dim myfile as string dim docapp as word. application dim docrange as word. range myfile = thisworkbook. path "\ Word document name" 'specifies the Word Document Set docapp = new word. application docapp. documents. open myfile for I = 1 to docapp. actived
Determine whether the text is selected: If selection. type = wdselectionip then msgbox "Nothing is selected"
Select cells in word: selection. selectcell
After moving to the selected content: selection. collapse direction: = wdcollapseendLocate the last row in word: selection. endkey unit: = wdstory or sendkeys "^ {end }"Move to the end of the document Ctrl + end Ctrl + home Ctrl + Pagedown Ctrl + PageupMo
① what are objects and collections
An object represents a Word element, such as a document, paragraph, bookmark, or individual character. A collection is also an object that contains multiple other objects, usually of the same type; for example, a collection object can contain all the bookmark objects in the document. By using properties and methods, you can modify individual objects, or you can modify the entire collection of objects.
② what is a p
Process name: wdout
Purpose: Use the defined template to automatically shape the template {????} And {photo} is replaced with the photo. If there is no photo, the replacement character is deleted.
Parameter: photofile -- the path string of the photo file, which is the complete absolute path. It does not determine whether the file exists. If the file does not exist, an error will occur.
Insert an image with only one sentenceWdapp. selection. inlineshapes. addpicture filename: = _Photofile, linkto
The following macro code, used in Word environments, automatically adds brackets or brackets to Word document references
' Addmarkref Macro
Dim Parag as Paragraph
Dim Selrge as Range
Dim Rge as Range
Dim Nfield as Integer
Dim Nparag as Integer
Set Selrge = Selection.Range
MsgBox "Should you choose a good reference before using the macro code?"
ActiveDocument.ActiveWindow.View.FieldShading = wdfield
Appearance:=xlscreen,Format: =xlpicture'Copy the rng area as a picture theActiveSheet.UsedRange.Rows (ActiveSheet.UsedRange.Rows.Count +1). Cells (1). Select'Select an empty cell - withACTIVESHEET.CHARTOBJECTS.ADD (0,0, rng. Width, rng. Height). Chart'Generate chart -. Paste'paste a picture into a chart -. Export Paths Replace(RNG. Address (0,0),":","-") Pic'export a chart as a picture file +. Parent.delete'Delete a Chart object - End with +Rng. Select'Select Rng Object A End If at
The code is as follows, if you want to judge the other format, please modify it yourself.
Option Explicit
Sub editpastespecial ()
"When the user clicks the paste-selective command, Word automatically calls this procedure
Dim Mydlg as Word.dialog
Dim Strdatatype as String
Set Mydlg = word.dialogs (wddialogeditpastespecial) "Paste Selective dialog box"
If mydlg.show =-1 Then
Strdatatype = ucase$ (mydlg.datatype) ' Get data type
End If
Set Mydl
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.