分享

vb生成操作保存提示excel文件

 hdzgx 2019-12-06
Private Sub 生成写入保存_Click()
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
xlApp.SheetsInNewWorkbook = 5
xlApp.Visible = True
 xlApp.Worksheets("Sheet1").Cells(1, 1) = 1
 xlApp.Worksheets("Sheet2").Cells(1, 1) = 2
 xlApp.Worksheets("Sheet3").Cells(1, 1) = 3
xlBook.saveas (App.Path & "\" & "zgx.xls")
xlApp.quit
End Sub


Private Sub 打开本地文件写入不提示保存退出_Click()

Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象

Set xlBook = xlApp.Workbooks.Open("C:\Users\Administrator\Desktop\ls\zgx.xls") '打开已经存在的EXCEL工件簿文件

xlApp.Visible = 0 '设置EXCEL对象可见(或不可见)

Set xlSheet = xlBook.Worksheets("sheet1") '设置活动工作表

xlSheet.Cells(3, 3) = "zhg2223333fgfx" '给单元格(row,col)赋值

xlSheet.Cells(2, 6).Interior.ColorIndex = 3 '设计单元格颜色i=1--56

xlApp.DisplayAlerts = False '保存/不保存Excel文件时不提示

xlBook.Close savechanges:=1

xlApp.DisplayAlerts = True '保存/不保存Excel文件时提示

xlApp.quit

Set xlApp = Nothing

End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多