Joke Collection Website - Blessing messages - Pass EXCEL data to WORD through VBA.
Pass EXCEL data to WORD through VBA.
Create a button in excel, double-click it and enter the following code:
Private subcommand button 1_Click ()
Turn off screen refresh.
"Continue to the next step when an error occurs" to catch the error.
Dim oSt is Range and wdDoc is Word. Document, wdRange is Word. range
myPath = ThisWorkbook。 Path and path. "\2.doc" ""defines the word file path, and the name is modified by myself. I set it to 2.doc.
Set wdDoc = GetObject(myPath)' open word.
Dim key(2)' defines an array,
Key( 1) = "abcdefg "'Data to be replaced.
key(2) = "hijklmn "
Set wdRange = wdDoc. Content provides the document content of word to wdrange.
For the period i = 1 to 2'
Use wdRange. find
. Text = key(i)' search
. replacement . text = key(I)& amp; IIF (I = 1, cell (1, 1). Value, cell (5, 2). Value)'
. Forward = true
. Wrap = wdFindContinue
. Format = false
. MatchCase = False
. MatchWholeWord = False
. MatchByte = True
. Match wildcard = False
. MatchSoundsLike = False
. MatchAllWordForms = False
End with ...
WD range. Find it. execute Replace:= WD Replace All ' Replace All。
then
WdDoc。 Save the save word.
WdDoc。 Close the close word.
Set wdDoc = Nothing.
Application.screenupdating = true' opens screen refresh.
End joint
After testing, it has met the requirements of the landlord. Please add points to adopt. Ha ha.
- Previous article:What should I do if I forget my mobile phone verification code?
- Next article:Classic Spring Festival couplets horizontal batch
- Related articles
- Lenovo a766 mobile phone signal is sometimes absent.
- Four words of New Year greetings
- How does Agricultural Bank cancel SMS notification?
- The letter from China Agricultural Bank Station is missing.
- Seeking efficient interactive short messages.
- How does Huawei enjoy 10 to wake up by voice?
- Pay a New Year's greeting to leaders on New Year's Eve.
- How to transcode people leaving the cabin in Zhengzhou
- How long does it take a friend to rent a plane?
- The glory of the king joint savings card of China Merchants Bank. How old can I apply?