怎样把VB程序的计算结果导入Word或Excel中?
2个回答
展开全部
给你一段代码,你自己研究下,这个是把系统表格里面的数据导出到Excel,可以举一反三
'将表格控件里的数据导出的函数
Public Sub ExportOut(fpsp As fpSpread, cDl As CommonDialog, m As Form, str As String)
On Error Resume Next
Dim i As Integer
Dim ss As Variant
fpsp.GetText 1, 1, ss
If Len(Trim(ss)) = 0 Then Exit Sub
'选择需要保存的文件
cDl.Filter = "Microsoft Excel文件(*.xls)|*.xls"
cDl.DialogTitle = "选择保存路径"
cDl.FileName = ""
cDl.ShowSave
If cDl.FileName = "" Then Exit Sub
If Dir(cDl.FileName) <> "" Then
If MsgBox("你选择的文件已经存在,是否覆盖该文件?", vbExclamation + vbYesNo) = vbNo Then
Exit Sub
Else
Kill (cDl.FileName)
End If
End If
Dim Titlename As String
Titlename = cDl.FileName
Dim xl As Excel.Application
Dim xlk As Excel.Workbook
Dim xlt As Excel.Worksheet
Set xl = New Excel.Application
Set xl = CreateObject("Excel.Application")
Set xlk = xl.Workbooks.Add
Set xlt = xlk.Worksheets(1)
xl.Visible = False
xlt.Activate
m.Caption = str & "——请稍候,正在导出。。。"
xl.Range(xl.Cells(2, 1), xl.Cells(Val(fpsp.MaxRows + 1), fpsp.MaxCols)).NumberFormatLocal = "@"
Dim po As Integer
For po = 0 To fpsp.MaxRows
For i = 1 To fpsp.MaxCols
fpsp.GetText i, po, ss
xl.Cells(po + 1, i) = ss
Next
Next
xlt.SaveAs Titlename
m.Caption = str & "——已成功导出到“" & Titlename & "”!"
xlk.Close
xl.Quit
Set xlt = Nothing
Set xlk = Nothing
Set xl = Nothing
End Sub
'将表格控件里的数据导出的函数
Public Sub ExportOut(fpsp As fpSpread, cDl As CommonDialog, m As Form, str As String)
On Error Resume Next
Dim i As Integer
Dim ss As Variant
fpsp.GetText 1, 1, ss
If Len(Trim(ss)) = 0 Then Exit Sub
'选择需要保存的文件
cDl.Filter = "Microsoft Excel文件(*.xls)|*.xls"
cDl.DialogTitle = "选择保存路径"
cDl.FileName = ""
cDl.ShowSave
If cDl.FileName = "" Then Exit Sub
If Dir(cDl.FileName) <> "" Then
If MsgBox("你选择的文件已经存在,是否覆盖该文件?", vbExclamation + vbYesNo) = vbNo Then
Exit Sub
Else
Kill (cDl.FileName)
End If
End If
Dim Titlename As String
Titlename = cDl.FileName
Dim xl As Excel.Application
Dim xlk As Excel.Workbook
Dim xlt As Excel.Worksheet
Set xl = New Excel.Application
Set xl = CreateObject("Excel.Application")
Set xlk = xl.Workbooks.Add
Set xlt = xlk.Worksheets(1)
xl.Visible = False
xlt.Activate
m.Caption = str & "——请稍候,正在导出。。。"
xl.Range(xl.Cells(2, 1), xl.Cells(Val(fpsp.MaxRows + 1), fpsp.MaxCols)).NumberFormatLocal = "@"
Dim po As Integer
For po = 0 To fpsp.MaxRows
For i = 1 To fpsp.MaxCols
fpsp.GetText i, po, ss
xl.Cells(po + 1, i) = ss
Next
Next
xlt.SaveAs Titlename
m.Caption = str & "——已成功导出到“" & Titlename & "”!"
xlk.Close
xl.Quit
Set xlt = Nothing
Set xlk = Nothing
Set xl = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |