用批处理打印一个文件夹下的几个子文件夹里的所有EXCEL表
一个文件夹有几个子文件夹,子文件夹中有几个EXCEL表,每个表都有固定的“总公司,省公司,分厂,门店”4个工作簿。而我想打印这个文件夹下的所有EXCEL表里面的分厂和门店...
一个文件夹有几个子文件夹,子文件夹中有几个EXCEL表,每个表都有固定的 “总公司,省公司,分厂,门店”4个工作簿。而我想打印这个文件夹下的所有EXCEL表里面的分厂和门店两个工作簿,其他两个工作簿不打印。谁能帮我也个批处理!万分感谢!
展开
2个回答
展开全部
批处理文件不太会编,不过你这个可以通过VBA来完成,我给你写了段代码,你试试
在excel表中按ALT+F11打开vba编辑器,插入模块,把下面代码粘上,再在excel里添加一个按钮,点右键指定宏“选择打印”,需要打印的时候就按一下就可以了
Sub 选择打印()
Dim sht As Worksheet
Dim lj, MyName As String
Dim Dic, i
Set a = CreateObject("Shell.Application")
Set b = a.BrowseForFolder(0, "选择文件夹", 0, 0)
If Not b Is Nothing Then lj = b.self.Path & "\"
Set b = Nothing
Set a = Nothing
Set Dic = CreateObject("Scripting.Dictionary")
Dic.Add (lj), ""
i = 0
Do While i < Dic.Count
ke = Dic.keys
MyName = Dir(ke(i), vbDirectory)
Do While MyName <> ""
If MyName <> "." And MyName <> ".." And Right(MyName, 4) = ".xls" Then
Workbooks.Open ("" & lj & "" & MyName & "")
For Each sht In Sheets
If sht.Name = "分厂" Or sht.Name = "门店" Then
sht.Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
Next
ActiveWindow.Close
End If
MyName = Dir
Loop
i = i + 1
Loop
End Sub
在excel表中按ALT+F11打开vba编辑器,插入模块,把下面代码粘上,再在excel里添加一个按钮,点右键指定宏“选择打印”,需要打印的时候就按一下就可以了
Sub 选择打印()
Dim sht As Worksheet
Dim lj, MyName As String
Dim Dic, i
Set a = CreateObject("Shell.Application")
Set b = a.BrowseForFolder(0, "选择文件夹", 0, 0)
If Not b Is Nothing Then lj = b.self.Path & "\"
Set b = Nothing
Set a = Nothing
Set Dic = CreateObject("Scripting.Dictionary")
Dic.Add (lj), ""
i = 0
Do While i < Dic.Count
ke = Dic.keys
MyName = Dir(ke(i), vbDirectory)
Do While MyName <> ""
If MyName <> "." And MyName <> ".." And Right(MyName, 4) = ".xls" Then
Workbooks.Open ("" & lj & "" & MyName & "")
For Each sht In Sheets
If sht.Name = "分厂" Or sht.Name = "门店" Then
sht.Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
Next
ActiveWindow.Close
End If
MyName = Dir
Loop
i = i + 1
Loop
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询