![](/img/trans.png)
[英]from Xcel Vba select a range of text from one Word document and copy into another Word document
[英]Copy Text from Range in Excel into Word Document
你怎么:
1)復制Excel文檔中某個范圍的文本。
2)打開Word文檔。
3)將文本插入到word文檔的特定部分。
問候
小城
編輯:這是方法
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim j As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\Files\DailyStrategy.doc")
With wrdDoc
If wrdDoc.Bookmarks.Exists("MarketCommentry")
Then wrdDoc.Bookmarks("MarketCommentry").Range.Text = shortString
wrdDoc.SaveAs "c:\temp\test.doc"
End If
' close the document
Set wrdDoc = Nothing
Set wrdApp = Nothing
End With
這是我為替換Word中的書簽文本編寫的一些代碼
Sub FillBookmark(ByRef wdDoc As Object, _
ByVal vValue As Variant, _
ByVal sBmName As String, _
Optional sFormat As String)
Dim wdRng As Object
'store the bookmarks range
Set wdRng = wdDoc.Bookmarks(sBmName).Range
'if the optional format wasn’t supplied
If Len(sFormat) = 0 Then
'replace the bookmark text
wdRng.Text = vValue
Else
'replace the bookmark text with formatted text
wdRng.Text = Format(vValue, sFormat)
End If
're-add the bookmark because the above destroyed it
wdRng.Bookmarks.Add sBmName, wdRng
End Sub
在這里更多細節
http://www.dailydoseofexcel.com/archives/2004/08/13/automating-word/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.