感謝GBKEE版主大力協助您的程式可以如小第所需運作,今想請版主再次協助更改開啟Documents.Open "d:\成果報 告.doc"原本只有一頁若改成二頁, 目前程式只能顯示第一頁(作用頁)因自己才疏學淺,找尋相關資料試了很久還是失敗,請版主再給予協助謝謝。
Dim Rng As Range
Private Sub TextBox1_Change()
If Trim(TextBox1) <> "" Then '去除兩旁空白字元後的TextBox1
Set Rng = Sheets("SHEET1").Range("a:a").Find(Trim(TextBox1), LOOKAT:=xlWhole)
' .Range("a:a") 尋找:身份證字號
If Not Rng Is Nothing Then
If MsgBox(TextBox1 & vbLf & "印列?", vbYesNo, "成果報 告") = vbYes Then Ex
End If
End If
End Sub
Private Sub Ex()
Dim AR, i As Integer
AR = Array("成果報 告", "H", "B", "D", "A", "I", "J", "K")
'表頭各欄位項目字串間隔請自行調整與顯示在 "成果報 告.DOC,的字串間隔一致
For i = 1 To UBound(AR)
AR(i) = Cells(1, AR(i)) & " : " & Rng.Cells(1, AR(i))
'導入 每欄位的表頭&":"&字串(內容)
Next
With CreateObject("WORD.APPLICATION")
.Visible = True
.Documents.Open "d:\成果報 告.doc"原檔案只有一頁現改有二頁,要這二頁能儲存在"d:\成果報 告.doc"
With .ActiveDocument
.Range(.Range.Start, .Range.End).Text = Join(AR, vbLf)
With .Range
.Font.Size = 16
.ParagraphFormat.Alignment = 0 'wdAlignParagraphLeft '靠左
With .Paragraphs(1).Range
.Font.Size = 24
.ParagraphFormat.Alignment = 1 ' wdAlignParagraphCenter '至中
End With
End With
.PrintOut '印列
.Close
End With
.Quit
End With
End Sub作者: GBKEE 時間: 2014-10-15 09:43