请问谁知道怎么用VB6新建一个EXCEL文件(不启动EXCEL),输入内容后保存?

oo渣渣oo 2000-08-10 10:54:00
...全文
419 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
mrlining 2000-08-10
  • 打赏
  • 举报
回复
最简单的方法就是引用Excel的对象库,在创建时虽然也启动Excel,但或把visible=false 和未启动Excel一样,其它的应和使用VBA一样简单。
Un1 2000-08-10
  • 打赏
  • 举报
回复
看看你的Email!
huntout 2000-08-10
  • 打赏
  • 举报
回复
我有一個取巧的方法︰先建好一個空excel文件作為模板,程序中要新建時,拷貝一個就好了!︰)
然後就可以用vba來操縱這個文件囉!
Maxwell 2000-08-10
  • 打赏
  • 举报
回复
好像是ODBC之类的东西支持Excel,总之是微软的东西,可以建立Excel格式的数据库.
DavidLiu 2000-08-10
  • 打赏
  • 举报
回复

Dim appExcel As Excel.Application
Dim bokExcel As Object
Dim shtExcel As Object
Dim lngRowNbr As Long
Dim lngColNbr As Long
Dim lngCtr_Row As Long
Dim lngCtr_Col As Long


On Error GoTo ErrorHandle

Set appExcel = New Excel.Application

Set appExcel = CreateObject("Excel.Application")

'For debug only if visible set to true
appExcel.Visible = False

'Add a new book
appExcel.Workbooks.Add
Set bokExcel = appExcel.ActiveWorkbook

Set shtExcel = bokExcel.Worksheets("Sheet1")

'Get data
lngRowNbr = mshfgCommLst.Rows
lngColNbr = mshfgCommLst.Cols

shtExcel.Cells.Font.Size = 8

shtExcel.Cells(1, 1) = Me.Caption

With shtExcel

'Title
For lngCtr_Col = 1 To lngColNbr
.Cells(2, lngCtr_Col).Value = mshfgCommLst.TextMatrix(0, (lngCtr_Col - 1))
Next lngCtr_Col



'Contents
If Me.QueryType = EnumQueryType.Detail Then
'Skip one row in mshfgCommLst (Date Value)
For lngCtr_Row = 3 To (3 + (lngRowNbr - 3)) '-3: 1 is for title , 1 is for Date value

For lngCtr_Col = 1 To lngColNbr
.Cells(lngCtr_Row, lngCtr_Col).Value = mshfgCommLst.TextMatrix((lngCtr_Row - 1), (lngCtr_Col - 1))
Next lngCtr_Col

Next lngCtr_Row

Else
For lngCtr_Row = 3 To (3 + (lngRowNbr - 2)) '-2: 1 is for title

For lngCtr_Col = 1 To lngColNbr
.Cells(lngCtr_Row, lngCtr_Col).Value = mshfgCommLst.TextMatrix((lngCtr_Row - 2), (lngCtr_Col - 1))
Next lngCtr_Col

Next lngCtr_Row


End If

End With


'Save
bokExcel.SaveAs FileName:=strFileName, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


'Quit
appExcel.Quit

On Error GoTo 0

OutputResult = True

Exit Function

ErrorHandle:
If Err.Number <> 1004 Then 'Cancel
MsgBox Err.Description, vbCritical, "Output result"
End If

If (appExcel Is Nothing = False) Then
appExcel.Quit
End If

On Error GoTo 0

OutputResult = False

7,759

社区成员

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

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