|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
sblisb 发表于 2013-4-12 08:59
谢谢,想在最后加一句打开生成的word文件,以备打印,如何写?
还有一个小问题,我把第一条打印状态 ... - Private Sub CommandButton1_Click()
- Dim f$, f2$, p$, arr, i&, j&, lr&, s$
- Application.ScreenUpdating = False
- arr = [a1].CurrentRegion
- lr = UBound(arr)
- For i = 2 To lr
- s = s & arr(i, 2)
- Next
- p = ThisWorkbook.Path & ""
- d = Format(Date, "yyyy年mm月dd日")
- f = p & "新建 Microsoft Word 文档.doc"
- f2 = p & s & ".doc"
- FileCopy f, f2
- With CreateObject("Word.Application")
- .Documents.Open f2
- .ActiveWindow.ActivePane.View.SeekView = 0 ' wdSeekMainDocument '设置位置在正文
- .Selection.WholeStory '全选
- .Selection.Copy '复制
- For i = 1 To lr - 2 '复制页
- .Selection.EndKey Unit:=6 'wdStory '光标置于文件尾
- .Selection.InsertBreak Type:=7 'wdPageBreak '分页
- .Selection.PasteAndFormat (0) '粘贴wdPasteDefault
- Next i
- For i = 2 To lr
- arr(i, 1) = WorksheetFunction.Text(arr(i, 1), "[DBNum1]yyyy年m月d日")
- For j = 1 To 8
- If j <> 3 Then
- .Selection.HomeKey Unit:=6
- If .Selection.Find.Execute("数据" & j) Then
- .Selection.Text = arr(i, j)
- If j = 2 Then .Selection.Font.Name = "隶书"
- End If
- End If
- Next
- Next
- .Documents.Save
- .Selection.HomeKey Unit:=6
- .Visible = True
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|