我有双显示器设置。我一直在研究4个excel工作簿,它将持续很长时间。 我想制作一个批处理文件或一个vb脚本文件来打开所需的文件并在监视器上垂直平铺它们。一台显示器上有2个文件,另一台上有2个文件。 我找到了这段代码
Dim shell
Set shell = CreateObject("Shell.Application")
shell.MinimizeAll
shell.Open "F:\FSA 30-08-15.xlsx"
shell.Open "F:\SMH 09-08-15.xlsx"
shell.Open "F:\MPP 23-08-15.xlsx"
shell.Open "F:\GIP 23-08-15.xlsx"
Wscript.Sleep 1000
shell.TileVertically
但这不会打开所有文件,也不会平铺它们。它只打开第一个文件。再次运行脚本会打开第二个文件,依此类推。但平铺文件无效。
答案 0 :(得分:0)
原因是您正在使用一个shell对象来打开多个Excel工作簿。因此,只创建一个Excel实例,并在该Excel实例中打开所有4个工作簿。您可能必须更新脚本,以便每个工作簿在单独的Excel实例中打开,然后您可以平铺它们。
Dim shell, objEx
Set shell = CreateObject("Shell.Application")
shell.MinimizeAll
Set objEx = CreateObject("Excel.Application")
objEx.Application.Visible = True
objEx.WorkBooks.Open "C:\Users\pankaj.jaju\Desktop\Work.xlsx"
Set objEx = Nothing
Set objEx = CreateObject("Excel.Application")
objEx.Application.Visible = True
objEx.WorkBooks.Open "C:\Users\pankaj.jaju\Desktop\portfolioIM_20150729_1318.xlsx"
Set objEx = Nothing
Set objEx = CreateObject("Excel.Application")
objEx.Application.Visible = True
objEx.WorkBooks.Open "C:\Users\pankaj.jaju\Desktop\Sample Conditional Formatting.xlsx"
Set objEx = Nothing
Set objEx = CreateObject("Excel.Application")
objEx.Application.Visible = True
objEx.WorkBooks.Open "C:\Users\pankaj.jaju\Desktop\Products.xlsx"
Set objEx = Nothing
Wscript.Sleep 5000
shell.TileVertically
set shell = nothing