|
本帖最后由 413191246se 于 2021-12-20 17:11 编辑
楼主 是否想要打印某个文件夹内的所有文件?请把要打印的所有文件放到一个新建文件夹内。楼主,请把你的代码赶快扔到 垃圾箱里!用我的。
下面是 杜老师 的代码,很高级的!你只需将单个文档处理的语句替换为打印即可。
即:将 .color=wdcolorRed 这句替换为 doc.printout 即可(但打印后,想关闭文档,会有提示,只须不保存即可),这是打印一份;如果想每个文档打印多份,可改为:
With doc
.PrintOut Copies:=3'打印 3 份
.Close SaveChanges:=wdDoNotSaveChanges
End With
***选择文件夹后,会自动把所有该文件夹及子文件夹下面的 Word 文档打印出来(无需选择文件):
- Sub LoopFolder_xiaohualu()
- '循环遍历文件夹及子文件夹
- Dim d, n&, m&, x&, mydir, dk, doc As Document, i&
- Set d = CreateObject("Scripting.Dictionary")
- d(SelectFolder) = ""
- Do While n < d.Count
- dk = d.keys
- mydir = Dir(dk(n), vbDirectory)
- Do While mydir <> ""
- If mydir <> "." And mydir <> ".." Then
- If GetAttr(dk(n) & mydir) = vbDirectory Then
- d(dk(n) & mydir & "") = ""
- m = m + 1
- Else
- x = x + 1
- If dk(n) & mydir Like "*.doc*" Then
- Set doc = Documents.Open(FileName:=dk(n) & mydir)
- doc.Content.Font.Color = wdColorRed
- doc.Close SaveChanges:=wdSaveChanges
- i = i + 1
- End If
- End If
- End If
- mydir = Dir
- Loop
- n = n + 1
- Loop
- Set d = Nothing
- Set dk = Nothing
- MsgBox "Done! Total " & x & " files! Word(*.doc*) " & i & " files!", 0 + 48
- End Sub
- Function SelectFolder() As String
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show Then SelectFolder = .SelectedItems(1) & "" Else End
- End With
- If MsgBox("Are you sure you want to select the folder " & vbCr & SelectFolder & " ?", 4 + 16) = vbNo Then End
- End Function
复制代码
|
评分
-
1
查看全部评分
-
|