作者在 2011-09-14 18:12:00 发布以下内容
我用的是VB6.0,我学着做了一段封装VBA的代码,在试运行的时候正常,但在生成工程文件的时候报错:“编译错误,用户类型定义未定义。” 请高手点一下。先谢过了。
Sub hongtong()
Dim excelApp As New Excel.Application
Dim excelWorkBook As Excel.Workbook
Dim excelWorksheet As Excel.Worksheet
Set excelWorkBook = excelApp.Workbooks.Add '创建新工作簿
Set excelWorksheet = excelWorkBook.Sheets(1)
excelWorksheet.Cells(2, 3) = "宏通" '写入数据
excelWorksheet.Cells(3, 4) = "zyg365" '写入数据
excelApp.Visible = True '显示excel界面,用于调试
excelWorkBook.PrintPreview '打印预览
excelWorkBook.PrintOut '打印输出
excelWorkBook.Saved = True
'excelWorkBook.Close '关闭工作薄
'excelApp.Quit '退出excel
End Sub
Dim excelApp As New Excel.Application
Dim excelWorkBook As Excel.Workbook
Dim excelWorksheet As Excel.Worksheet
Set excelWorkBook = excelApp.Workbooks.Add '创建新工作簿
Set excelWorksheet = excelWorkBook.Sheets(1)
excelWorksheet.Cells(2, 3) = "宏通" '写入数据
excelWorksheet.Cells(3, 4) = "zyg365" '写入数据
excelApp.Visible = True '显示excel界面,用于调试
excelWorkBook.PrintPreview '打印预览
excelWorkBook.PrintOut '打印输出
excelWorkBook.Saved = True
'excelWorkBook.Close '关闭工作薄
'excelApp.Quit '退出excel
End Sub