我从网上找到了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
我该怎么修改上面的代码?
谢谢

解决方案 »

  1.   


    Dim xlapp As New Excel.Application
    Dim xlbook As Excel.Workbook
    Dim xlsheet As Excel.WorksheetSet xlbook = xlapp.Workbooks.Open("C:\windows\模板.xls")
    Set xlsheet = xlbook.Worksheets("sheet1")xlapp.Visible = True
    xlsheet.PrintPreview
    xlbook.Close (False)
    xlapp.QuitSet xlsheet = Nothing
    Set xlbook = Nothing
    Set xlapp = Nothing