首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB预览指定的excel文件,该怎么处理

2012-02-25 
VB预览指定的excel文件我从网上找到了vb预览excel文件的代码,Private Sub Form_Load()Dim xlappAs New Exc

VB预览指定的excel文件
我从网上找到了vb预览excel文件的代码,
Private Sub Form_Load()
Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook
Dim xlsheet As New Excel.Worksheet
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets("sheet1")
xlsheet.Cells(1, 1) = "col1 "
xlsheet.Cells(1, 2) = "col2 "
xlsheet.Cells(1, 3) = "col3 "
xlapp.Visible = True
xlsheet.PrintPreview
xlbook.Close (False)
xlapp.Quit
Set xlsheet = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
End Sub

但他的是临时创建的excel,我想预览C:\windows\模板.xls
我该怎么修改上面的代码?
谢谢


[解决办法]

VB code
Dim xlapp As New Excel.ApplicationDim xlbook As Excel.WorkbookDim xlsheet As Excel.WorksheetSet xlbook = xlapp.Workbooks.Open("C:\windows\模板.xls")Set xlsheet = xlbook.Worksheets("sheet1")xlapp.Visible = Truexlsheet.PrintPreviewxlbook.Close (False)xlapp.QuitSet xlsheet = NothingSet xlbook = NothingSet xlapp = Nothing 

热点排行