V d? v? m VBA ? chn vn b?n vo m?t ti li?u trong Word 2000

D?ch tiu ? D?ch tiu ?
ID c?a bi: 212682 - Xem s?n ph?m m bi ny p d?ng vo.
M?t phin b?n Microsoft Word 98 Macintosh Edition c?a bi vi?t ny, xem cc 183866.
M?t phin b?n Microsoft Word 97 c?a bi vi?t ny, xem cc 161407.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

Bi vi?t ny cung c?p m?t s? Visual Basic cho cc ?ng d?ng v d? v? m dng cc L?a ch?n b?t ?ng s?n v cc Ph?m vi ?i t?ng ? chn vn b?n vo m?t ti li?u.

THNG TIN THM

Microsoft cung c?p l?p tr?nh v d? ? minh ho? ch?, khng c b?o hnh ho?c th? hi?n hay ng? ?. i?u ny bao g?m, nhng khng gi?i h?n, b?o ?m ng? ? kh? nng bn hng ho?c cho m?t m?c ch c? th?. Bi vi?t ny gi? ?nh r?ng b?n ? quen thu?c v?i ngn ng? l?p tr?nh m ang ?c ch?ng minh v v?i nh?ng cng c? ?c s? d?ng ? t?o ra v g? l?i th? t?c. Microsoft h? tr? cc k? s c th? gip gi?i thch cc ch?c nng c?a m?t th? t?c c? th?, nhng h? s? khng s?a ?i cc v d? ? cung c?p thm ch?c nng ho?c xy d?ng quy tr?nh ? p ?ng cc yu c?u c? th? c?a b?n.

S? d?ng l?a ch?n ?i t?ng v phng php TypeText

Chn vn b?n ? ch? r?. Nu ReplaceSelection b?t ?ng s?n l S? th?t, cc l?a ch?n ?c thay th? b?ng vn b?n ? ch? r?. N?u ReplaceSelection b?t ?ng s?n la Sai, cc vn b?n ? ch? r? chn tr?c khi l?a ch?n.

? bi?t thm thng tin v? b?t ?ng s?n ReplaceSelection, trong Visual Basic Editor, b?m vo Tr? gip Microsoft Visual Basic trn cc Tr giup tr?nh n, lo?i B?t ?ng s?n ReplaceSelection trong tr? l? vn ph?ng ho?c thu?t s? tr? l?i, v sau b?m Tim kim ? xem cc ch? ?.
Sub TypeTextMethod()
  Dim MyText As String
  MyText = "<Replace this with your text>"
  Selection.TypeText (MyText)
End Sub
				

B?ng cch s? d?ng cc ?i t?ng ph?m vi

V d? sau thay th? ton b? n?i dung c?a m?t ti li?u v?i cc l?i "Replaced" b?t k? v? tr hi?n t?i c?a i?m chn.

Sub RangeProperty()
  ' Range Example:
  ActiveDocument.Range.Text = "Replaced"
End Sub
				

S? d?ng ph?m vi ho?c l?a ch?n ?i t?ng v?i phng php InsertAfter/InsertBefore

InsertAfter phng php v d?:

Chn vn b?n ? ch? ra ? ph?n cu?i c?a m?t ph?m vi ho?c l?a ch?n.
Sub InsertAfterMethod()
  Dim MyText As String
  Dim MyRange As Object
  Set MyRange = ActiveDocument.Range
  MyText = "<Replace this with your text>"
  ' Selection Example:
  Selection.InsertAfter (MyText)
  ' Range Example:
  ' (Inserts text at the current position of the insertion point.)
  MyRange.Collapse
  MyRange.InsertAfter (MyText)
End Sub
				
InsertBefore phng php v d?:

Chn vn b?n ? ch? ?nh t?i ?u c?a m?t lo?t ho?c l?a ch?n. Sau khi phng php ny ?c p d?ng, ph?m vi ho?c l?a ch?n m? r?ng ? bao g?m cc m?i vn b?n.
Sub InsertBeforeMethod()
   Dim MyText As String
   Dim MyRange As Object
   Set MyRange = ActiveDocument.Range
   MyText = "<Replace this with your text>"
   ' Selection Example:
   Selection.InsertBefore (MyText)
   ' Range Example: Inserts text at the beginning
   ' of the active document.
   MyRange.InsertBefore (MyText)
End Sub
				

Chn m?t ch thch vo m?t ti li?u b?ng cch s? d?ng ?i t?ng ph?m vi ho?c l?a ch?n

Chn m?t b?nh lu?n ? v? tr hi?n t?i c?a i?m chn.
Sub CommentsCollectionObject()
   Dim MyText As String
   Dim MyRange As Object
   Set MyRange = ActiveDocument.Range
   MyText = "<Replace this with your text>"
  ' Selection Example:
  Selection.Comments.Add Range:=Selection.Range, Text:=MyText
  ' Range Example:
  MyRange.Comments.Add Range:=Selection.Range, Text:=MyText
End Sub
				

Chn m?t tr?ng vo m?t ti li?u b?ng cch s? d?ng ?i t?ng ph?m vi ho?c l?a ch?n

Chn m?t tr?ng ? v? tr hi?n t?i c?a i?m chn.
Sub FieldsCollectionObject()
   Dim MyText As String
   Dim MyRange As Object
   Set MyRange = Selection.Range
   MyText = "<Replace this with your text>"
   ' Selection Example:
   Selection.Fields.Add Range:=Selection.Range, _
      Type:=wdFieldQuote, Text:=MyText
   ' Range Example:
    Range.Fields.Add Range:=Selection.Range, _
      Type:=wdFieldQuote, Text:=MyText
End Sub
				
V d? ny chn m?t l?nh v?c cng th?c. K?t qu? ?nh d?ng v?i m?t ?ng la d?u hi?u.

Sub InsertFormulaMethod()
   Selection.InsertFormula Formula:="=100,000.0-45,000.0", _
      NumberFormat:="$#,##0.0"
End Sub
				

Sao chp cc vn b?n, bao g?m c? cc ?nh d?ng, c?a m?t lo?t cc vn b?n

B?t ?ng s?n ny tr? v? m?t Ph?m vi ?i t?ng v?i cc k? t? ?nh d?ng v vn b?n t? ph?m vi quy ?nh ho?c l?a ch?n. ?nh d?ng o?n ?c bao g?m trong cc ?i t?ng ph?m vi n?u c m?t d?u o?n trong ph?m vi ho?c l?a ch?n. Khi b?n thi?t l?p ny b?t ?ng s?n, cc vn b?n trong ph?m vi ?c thay th? v?i ?nh d?ng vn b?n. N?u b?n khng mu?n thay th? vn b?n hi?n hnh, s? d?ng cc S?p ? phng php tr?c khi s? d?ng ti s?n ny.
Sub FormattedTextProperty()
   ' This example copies the first paragraph in the document, including
   ' its formatting, and inserts the formatted text at the insertion
   ' point.
   Selection.Collapse Direction:=wdCollapseStart
   Selection.FormattedText = ActiveDocument.Paragraphs(1).Range
End Sub
				

?t vn b?n vo m?t ?u trang hay chn trang

LU ?: The HeaderFooter b?t ?ng s?n ?i h?i r?ng vi?c l?a ch?n ?c ?t trong m?t ?u trang hay chn trang, ho?c l?i s? x?y ra.
Sub HeaderFooterProperty()
   Dim MyText As String
   MyText = "<Replace this with your text>"
   ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
   Selection.HeaderFooter.Range.Text = "MyText"
   ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
				
V d? sau thay ?i cc vn b?n c?a c? hai tiu ? chnh v cc chnh chn cho ph?n ?u tin c?a ti li?u hi?n ho?t.
Sub HeaderFooterObject()
  Dim MyText As String
  MyHeaderText = "<Replace this with your text>"
  MyFooterText = "<Replace this with your text>"
  With ActiveDocument.Sections(1)
    .Headers(wdHeaderFooterPrimary).Range.Text = MyHeaderText
    .Footers(wdHeaderFooterPrimary).Range.Text = MyFooterText
  End With
End Sub
				

B?ng cch s? d?ng ?i t?ng ph?m vi ho?c l?a ch?n ? chn m?t ngy b?ng cch s? d?ng l?nh v?c th?i gian

V d? ny chn m?t l?nh v?c th?i gian cho ngy hi?n t?i. M?t k?t qu? c th? c th? "18 thng 11 nm 1996."
Sub InsertDateTimeMethod()
   Dim MyRange As Object
   Set MyRange = Selection.Range
   ' Selection Example:
   Selection.InsertDateTime DateTimeFormat:="MMMM dd, yyyy", _
   InsertAsField:=True
   ' Range Example:
   MyRange.InsertDateTime DateTimeFormat:="MMM dd, yyyy", _
   InsertAsField:=True
End Sub
				

B?ng cch s? d?ng ?i t?ng ph?m vi ho?c l?a ch?n ? chn m?t o?n vn m?i

V d? ny chn m?t o?n vn m?i bn d?i v? tr hi?n t?i c?a i?m chn.
Sub InsertParagraphMethod()
   Dim MyRange As Object
   Set MyRange = ActiveDocument.Range
   ' Selection Example:
   Selection.InsertParagraph
   ' Range Example:
   MyRange.Collapse Direction:=wdCollapseStart
   MyRange.InsertParagraph
End Sub
				

B?ng cch s? d?ng ?i t?ng ph?m vi ho?c l?a ch?n ? chn bi?u t?ng

V d? ny chn m?t i ?ng ?u m?i tn ? i?m chn.
Sub InsertSymbolMethod()
   Dim MyRange As Object
   Set MyRange = ActiveDocument.Range
   ' Selection Example:
   Selection.InsertSymbol CharacterNumber:=171, _
      Font:="Symbol", Unicode:=False
   ' Range Example:
   MyRange.Collapse Direction:=wdCollapseStart
   MyRange.InsertSymbol CharacterNumber:=171, _
      Font:="Symbol", Unicode:=False
End Sub
				

B?ng cch s? d?ng ?i t?ng ph?m vi ho?c l?a ch?n ? dn t? b?ng t?m

V d? ny chn vn b?n ?c ?t trn b?ng t?m vo v? tr hi?n t?i c?a i?m chn.
Sub PasteMethod()
   Dim MyRange As Object
   Set MyRange = Selection.Range
   ' Selection Example:
   Selection.Paste
   ' Range Example:
   MyRange.Collapse Direction:=wdCollapseStart
   MyRange.Paste
End Sub
				

? bi?t thm chi ti?t v? vi?c s? d?ng cc ?i t?ng ph?m vi, trong Visual Basic Editor, nh?p vo Tr? gip Microsoft Visual Basic trn cc Tr giup tr?nh n, lo?i ?i t?ng ph?m vi trong tr? l? vn ph?ng ho?c thu?t s? tr? l?i, v sau b?m Tim kim ? xem cc ch? ?.

? bi?t thm chi ti?t v? vi?c s? d?ng l?a ch?n ?i t?ng, trong Visual Basic Editor, nh?p vo Tr? gip Microsoft Visual Basic trn cc Tr giup tr?nh n, lo?i L?a ch?n ?i t?ng trong tr? l? vn ph?ng ho?c thu?t s? tr? l?i, v sau b?m Tim kim ? xem cc ch? ?.

? bi?t thm chi ti?t v? cch s? d?ng m?u m? trong bi vi?t ny, b?m s? bi vi?t d?i y ? xem bi vi?t trong c s? ki?n th?c Microsoft:
212536OFF2000: Lm th? no ? ch?y m?u m? t? bi vi?t c s? ki?n th?c

THAM KH?O

? bi?t thm chi ti?t v? vi?c nh?n tr? gip v?i Visual Basic cho cc ?ng d?ng, xin vui l?ng xem bi vi?t sau trong c s? ki?n th?c Microsoft:
226118 OFF2000: L?p tr?nh ti nguyn cho Visual Basic cho cc ?ng d?ng

Thu?c tnh

ID c?a bi: 212682 - L?n xem xt sau cng: 18 Thang Chin 2011 - Xem xt l?i: 3.0
p d?ng
  • Microsoft Word 2000 Standard Edition
T? kha:
kbdtacode kbhowto kbmacroexample kbprogramming kbmt KB212682 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:212682

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com