如何调用execel!

vickluo 2003-10-09 07:39:01
如何用vb调用execel?
...全文
66 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
vickluo 2003-10-10
  • 打赏
  • 举报
回复
谢谢!
Wizard1979 2003-10-10
  • 打赏
  • 举报
回复
主要代码如下:
Private Sub lsOutPut()
Dim szWkSht As Worksheet '创建工作页面
On Error Resume Next

'初期処理
Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook = ExcelApp.Workbooks.Add '添加EXCEL文件
Set ExcelSheet = ExcelBook.Worksheets(1) '添加工作页面
ExcelSheet.Activate '激活工作页面
'シートを削除する
ExcelApp.DisplayAlerts = False
'无用的页面删除
For Each szWkSht In ExcelBook.Worksheets
szWkSht.Delete
Next szWkSht
On Error GoTo ErrorHandler
mintSheetNo = 1
'调用创建页面函数(具体内容在下面)
Call lsMakeSheet
'数据设定(具体内容省略)
Call lsGetData

'Sheetを削除する
' For Each szWkSht In ExcelBook.Worksheets
' If szWkSht.Name = "Sheet3" Then
' szWkSht.Delete
' End If
' Next szWkSht
' ExcelSheet.Name = "Sheet1" '*** DEL 20020925 higashi ***
ExcelApp.Visible = True
ExcelApp.DisplayAlerts = True
'清空各个对象
Set ExcelApp = Nothing
Set ExcelBook = Nothing
Set ExcelSheet = Nothing

Exit Sub

'エラー処理
ErrorHandler:
Set ExcelApp = Nothing
Set ExcelBook = Nothing
Set ExcelSheet = Nothing

'エラーのときメッセージ表示してABORT
Call gsAbort("lsOutPut")
End Sub

Private Sub lsMakeSheet()
Dim output As Excel.Range
Dim wstrSql As String
Dim wstrsql1 As String
Dim wstrsql2 As String
Dim wstrsql3 As String
Dim wstrsql4 As String
Dim wstrsql5 As String
Dim wobjObj As Object
Dim wobjObj1 As Object
Dim wobjObj2 As Object
Dim wobjObj3 As Object
Dim wobjObj4 As Object
Dim wobjObj5 As Object
Dim wintJ As Integer
Dim wintL As Integer
Dim wstr1 As String
Dim wstr2 As String
Dim wstr3 As String
Dim wstr4 As String
Dim wstrExc As String
Dim wlngK As Long
Dim wintM As Integer
Dim wstrSDate As String
Dim wstrEDate As String
Dim wstrcenterheader As String
Dim wstrcenterheader1 As String
Dim wbolFlg As Boolean
Dim wintK As Integer
Dim wintI As Integer
Dim wintDate As Integer
Dim wbolFlg1 As Boolean
Dim wlngYokuki As Long

On Error GoTo ErrorHandler

wintDate = CLng(Mid(CStr(mlngDate), 7, 2))
'シートを追加する
' ExcelBook.Sheets.Add after:=ExcelBook.Worksheets(ExcelBook.Worksheets.Count) *** DEL 20020925 higashi ***
Set ExcelSheet = ExcelBook.Worksheets(ExcelBook.Worksheets.Count)
'行の高設定
Set output = ExcelSheet.Rows("2:2")
output.RowHeight = 22.5
Set output = ExcelSheet.Rows("5:5")
output.RowHeight = 12
'列の幅設定
Set output = ExcelSheet.Columns("A:A")
output.ColumnWidth = 5
Set output = ExcelSheet.Columns("B:B")
output.ColumnWidth = 30
Set output = ExcelSheet.Columns("C:C")
output.ColumnWidth = 3
Set output = ExcelSheet.Columns("D:D")
output.ColumnWidth = 8
wstrExc = "A4:" & wstr1 & wstr2 & CLng(mintRecsu + 5)
Set output = ExcelSheet.Range(wstrExc)
With output.Font
.Name = "MS ゴシック"
.Size = 10
.Underline = xlUnderlineStyleNone
End With
Exit Sub

'エラー処理
ErrorHandler:
'エラーのときメッセージ表示してABORT
Call gsAbort("lsMakeSheet")
End Sub



809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧