标题: 为什么别人可以导出excel,我的不可以?不知道哪出错了 [打印本页] 作者: luhao 时间: 2009-3-22 15:45 标题: 为什么别人可以导出excel,我的不可以?不知道哪出错了 Public Function GetFolder() As String
'文件及文件夹路径函数
Dim dlgOpen As FileDialog
Dim i As Long, j As Long
Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = True
.Show
End With
i = dlgOpen.SelectedItems.Count
If i > 0 Then
GetFolder = ""
For j = 2 To i
GetFolder = GetFolder & dlgOpen.SelectedItems(j) & ";"
Next
j = 1
GetFolder = GetFolder & dlgOpen.SelectedItems(j)
Else
GetFolder = CurDir() & "\"
End If
Set dlgOpen = Nothing
End Function
======================
Private Sub cmd导出_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim rs As New ADODB.Recordset
Dim sql As String
Dim i As Long
Dim fname As String
Dim shtname As String
On Error GoTo cmd导出_Err
fname = GetFolder '打开文件夹并选取文件
shtname = InputBox("请选择表:", "表选择窗体", "Sheet1") '指定导出到的工作表(Sheet)名称
sql = "select * from QY_Excel盘点 where 流水单号ID =" & Me.流水单号
rs.Open sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic '打开记录集
Set xlApp = CreateObject("Excel.Application") '创建一个Excel实例
xlApp.Application.Visible = True '使Excel可见
Set xlBook = xlApp.Workbooks.Open(fname) '打开Excel工作簿
'导出主表
xlBook.Application.Sheets(shtname).Select '按指定名称选择工作表
xlBook.Application.Range("A1").Value = "流水单号"
xlBook.Application.Range("A2").Value = "备 注"
xlBook.Application.Range("C1").Value = "盘点日期"
xlBook.Application.Range("B1").Value = Me.流水单号
xlBook.Application.Range("B2").Value = Me.备注
xlBook.Application.Range("D1").Value = Me.盘点日期
'导出子表
xlBook.Application.Cells(3, 1).Value = "材质名称"
xlBook.Application.Cells(3, 2).Value = "原料大类名称"
xlBook.Application.Cells(3, 3).Value = "账面数量"
xlBook.Application.Cells(3, 4).Value = "实际数量"
xlBook.Application.Cells(3, 5).Value = "差异数量"
For i = 1 To rs.RecordCount
xlBook.Application.Cells(i + 3, 1).Value = rs("材质名称")
xlBook.Application.Cells(i + 3, 2).Value = rs("原料大类名称")
xlBook.Application.Cells(i + 3, 3).Value = rs("账面数量")
xlBook.Application.Cells(i + 3, 4).Value = rs("实际数量")
xlBook.Application.Cells(i + 3, 5).Value = rs("差异数量")
rs.MoveNext
Next
xlApp.Quit
rs.Close
Set xlApp = Nothing
Set xlBook = Nothing
cmd导出_Exit:
Exit Sub
cmd导出_Err:
MsgBox "数据错误,请检查!"
Resume cmd导出_Exit
End Sub
==================
为什么别人可以导出excel,我的不可以??????????作者: todaynew 时间: 2009-3-22 16:06
呵呵,把实例传上来我给你看看。作者: xluuu 时间: 2009-8-28 15:27
学习