dim oExcel,oWb,oSheet,temp,fso,os
Set oExcel= CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Const TemporaryFolder = 2
Set temp = fso.GetSpecialFolder(TemporaryFolder)
Set oWb = oExcel.Workbooks.Open(temp & "\test.xls")
oExcel.Application.Visible=True
For i=1 To oWb.Sheets.Count
Set oSheet = oWb.WorkSheets(i)
oSheet.printpreveiw
Next
oExcel.Quit现在有这么个要求: 操作excel打印预览所有的工作表,就相当于选中所有工作表,然后打印预览的效果求高手解惑!!!!!

解决方案 »

  1.   

    用Excel录制宏,把你需要的操作执行一遍,停止录制后参考生成的宏写VB代码就可以了。
      

  2.   

    不行诶....不是要手动选择,是要不管一张excel有多少sheet都打印(对所有不同的excel都匹配)
      

  3.   

    ...
    Dim aSheets() As Variant
    Dim i As Long
    ReDim aSheets(1 To oWb.Sheets.Count)
    For i = 1 To oWb.Sheets.Count
        aSheets(i) = oWb.Sheets(i).Name
    NextSheets(aSheets).PrintPreview
      

  4.   

    Dim oExcel,oWb,oSheet,temp,fso,os
    Set oExcel= CreateObject("Excel.Application")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Const TemporaryFolder = 2
    Set temp = fso.GetSpecialFolder(TemporaryFolder)
    Set oWb = oExcel.Workbooks.Open(temp & "\test.xls")
    oExcel.Application.Visible=True
    Dim aSheets() As Variant
    Dim i As Long
    ReDim aSheets(1 To oWb.Sheets.Count)
    For i = 1 To oWb.Sheets.Count
        aSheets(i) = oWb.Sheets(i).Name
    NextSheets(aSheets).PrintPreview
    os.PrintPreview楼上大神,还是不行厄=  =
      

  5.   

    那就用For Each方式循环遍列一个Excel文件中的所有Sheets,然后在显示打印预览即可。
      

  6.   

    oWb.Sheets(aSheets).PrintPreview '<-加个前缀限定