'用输出到excel的方法打印
Dim Ex As New Excel.Application
Dim ExW As Excel.Workbook
Dim Exs As Excel.Worksheet......
exs.Range("d7:e8").MergeCells = True

解决方案 »

  1.   

    非常感谢你提供的信息,但是如何能让EXCEL不显示,而EXCEL打印预览的结果显示出来,该如何设置呢?请给出代码!!
    在此感谢!!!
      

  2.   

    Private Sub Command1_Click()
        On Error Resume Next    Dim xlApp As New Excel.Application
        Dim xlBook As Excel.Workbook
        Dim xlSheet As Excel.Worksheet
        Dim i, j As Integer
        Dim iXlRow As Integer
        Set xlApp = GetObject(, "Excel.Application")
        If Err.Number = 429 Then
            '***************************************************************
            ' Excel is NOT running, so create a new instance
            '***************************************************************
            On Error Resume Next
            Set xlApp = CreateObject("Excel.Application")
            Set xlBook = xlApp.Workbooks.Add
        End If
        
        If Err.Number <> 429 And Err.Number <> 0 Then
            MsgBox "打开 Excel 时发生错误!请检查是否正确安装了 Excel 2000 或更高版本!", vbExclamation, App.Title
        End If
        Err.Clear
        Set xlSheet = xlApp.Worksheets.Add
        If Err.Number Then
            Set xlBook = xlApp.Workbooks.Add
            Set xlSheet = xlApp.Worksheets.Add
        End If
        On Error GoTo ErrH
        '*******************************************************************
        ' Make sure Excel is visible
        '*******************************************************************    xlApp.Visible = False'不可见
        xlSheet.Cells.Font.Size = 10
        xlSheet.Cells.HorizontalAlignment = xlCenter
        
        With xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 3))
            .Merge
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
        xlSheet.Cells(1, 1) = "WELCOME EXCEL2000"
        xlSheet.Cells(1, 1).Font.Size = 12
        xlSheet.Cells(1, 1).Font.Bold = True
        
        xlSheet.Range(xlSheet.Cells(3, 1), xlSheet.Cells(4, 3)).BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
        xlSheet.Range(xlSheet.Cells(3, 1), xlSheet.Cells(4, 3)).Borders(xlInsideHorizontal).LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(3, 1), xlSheet.Cells(4, 3)).Borders(xlInsideHorizontal).Weight = xlThin
        xlSheet.Range(xlSheet.Cells(3, 1), xlSheet.Cells(4, 3)).Borders(xlInsideVertical).LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(3, 1), xlSheet.Cells(4, 3)).Borders(xlInsideVertical).Weight = xlThin
        '####到最适合列宽
        xlSheet.Columns.AutoFit
        
        With xlSheet.PageSetup
            .TopMargin = 20
            .LeftMargin = 20
            .BottomMargin = 75
            .RightMargin = 20
            .Orientation = xlLandscape
            .CenterHorizontally = True
            .RightFooter = "第&P页,共&N页"
        End With
        xlApp.Visible = True'可见
        xlSheet.PrintPreview
        
        
        Set xlSheet = Nothing
        Set xlApp = Nothing
        Exit Sub
    ErrH:
        MsgBox "打开 Excel 时发生错误!请检查是否正确安装了 Excel 2000 或更高版本!如Excel 正在运行,请先关闭!" & Err.Description, vbExclamation, App.Title
    End Sub
      

  3.   

    谢谢这位高手的代码,可是xlApp.Visible = FALSE这段代码不好用。请问一个为什么。
      

  4.   

    exs.Range("d7:e8").MergeCells = True在这句话中谁能解决一下,如何把D7中的7这个具体的值变为一个变量仍可用。在线等候着!!急急急
    谢谢
      

  5.   

    调出WORD文档
    Dim WordA As Word.Application
    Dim doc As Word.Document
        Set WordA = New Word.Application
        Set doc = WordA.Documents.Add
    doc.open app.path & "\tmp\tmp1.doc"