插入文本這應該可以幫助你的方式代碼。
Sub ExcelToWord()
' define all Excel variables you are going to use:
Dim Wb As Workbook
Dim Ws As Worksheet
Dim Cell As Range
' define all Word variables you are going to use:
' since you are running the code from Excel
' you must specify "Word" for each data type
Dim WdApp As Word.Application
Dim Doc As Word.Document
' define variables which you can use in either application:
' (if you aren't sure, define separate ones)
Dim Tmp As String
Dim R As Long
Dim i As Integer
' replace this name with the name & path of your own Word document
Tmp = "E:\PVT Archive\Class 1\1-2017 (Jan 2019)\STO 170317.docm"
If Dir(Tmp) = "" Then ' Check if the file exists
MsgBox "The file doesn't exist.", _
vbInformation, "Invalid file or path name"
Exit Sub
End If
Set WdApp = CreateObject("Word.Application") ' open Word
WdApp.Visible = True
Set Doc = WdApp.Documents.Open(Tmp) ' open the document
If Not Doc.Bookmarks.Exists("Amark") Then
MsgBox "The bookmark 'Amark' doesn't exist.", _
vbInformation, "Can't find bookmark"
Exit Sub
End If
Set Wb = ActiveWorkbook
Set Ws = Wb.Worksheets("DIP Main")
Tmp = Ws.Cells(25, "C").Value
Doc.Bookmarks("Amark").Range.Text = Tmp
End Sub
請注意,書籤將被替換爲下一個。此後不存在。如果你想重新使用它,你必須使用代碼重新設置它。
我將如何使它等於存儲在字符串中的值? –