'用输出到excel的方法打印
Dim Ex As New Excel.Application
Dim ExW As Excel.Workbook
Dim Exs As Excel.Worksheet......
exs.Range("d7:e8").MergeCells = True
Dim Ex As New Excel.Application
Dim ExW As Excel.Workbook
Dim Exs As Excel.Worksheet......
exs.Range("d7:e8").MergeCells = True
在此感谢!!!
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
谢谢
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"