无需询问即可保存excel [英] Save excel without asking

查看:70
本文介绍了无需询问即可保存excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我将一些数据导出到excelsheet并打印.

效果很好,但是现在我想保存它而不问我是否想要.

当我放入workBook.Saved = False时,它会保存数据,但会询问我.
我该如何更改.

这是我的代码


Hi,

I export some data to a excelsheet and print it .

Works great , but now i want to save it without asking if i want to.

When i put workBook.Saved = False it save''s the data but it ask me.
How do i change this .

This is my code


InitializeComponent()
       Dim AppExcel As Object
       Dim workBook As Object
       AppExcel = CreateObject("Excel.Application")


       workBook = AppExcel.Workbooks.Open(My.Application.Info.DirectoryPath & "\haven.xls")
       AppExcel.Visible = False
       Worksheets = workBook.worksheets

       AppExcel.Visible = True
       Label1.Text = Worksheets("Haven").Cells(6, 8).text



       Worksheets("Haven").Cells(100, 9).value =Papieren.TextBox19.Text
       Worksheets("Haven").Cells(7, 8).value = Papieren.TextBox19.Text
       

           Worksheets("Haven").PrintOut()

 




       Dim oXL As Application
       Dim oWB As Excel.Workbook
       Dim oSheet As Excel.Workbook
       Dim oRng As Excel.Range


       workBook.Saved = False


       
       oRng = Nothing
       oSheet = Nothing
       oWB = Nothing
       AppExcel.Quit()
       oXL = Nothing

       GC.Collect()
       Form16.Show()
       Me.Close()

   End Sub

推荐答案

如何保存Excel文件?
使用工作簿方法:
1)对于现有文件:Save()

2)对于新版本:SaveAS("fullfilename")

意见建议:
1)变体名称不能与对象名称(工作簿,工作表等)相同,
2)始终使用Try... Catch... End Try

How to save Excel file?
Use workbook methods:
1) for existing file: Save()
or
2) for the new one: SaveAS("fullfilename")

Suggestions:
1) Variant''s name can''t be the same as the objects names (workbook, worksheet, etc.),
2) Always use Try... Catch... End Try block

Dim xap As Object = Nothing
Dim wbk As Object = Nothing
Dim wsh As Object = Nothing

Try
    xap = CreateObject("Excel.Application")
    wbk = xap.Workbooks.Open(My.Application.Info.DirectoryPath & "\haven.xls")
    wsh = wbk.Worksheets("Haven")
    'read value
    Label1.Text = wsh.Cells(6, 8).Value 'or  wsh.Range("F8").Value
    'save values
    wsh.Cells(100, 9).Value = Papieren.TextBox19.Text
    wsh.Cells(7, 8).Value = Papieren.TextBox19.Text
    'do you really want to print document without print preview?
    wsh.PrintOut()
    wbk.Save() 
    xap.Quit()

Catch ex As Exception
    MsgBox(ex.Message, ..., "Error")

Finally
    wsh = Nothing
    wbk = Nothing
    xap = Nothing
End Try


你好

我不知道基本语法,但是这是我在MFC程序中使用的功能:

调用保存功能之前
ExcelApp.put_DisplayAlerts(FALSE);

保存文件

调用保存功能后
ExcelApp.put_DisplayAlerts(TRUE);

HTH

蒂埃里(Thierry)
Hello

I don''t know Basic syntax but here here is the function I use in MFC program:

Before Calling the Save Function
ExcelApp.put_DisplayAlerts( FALSE);

Save File

After Calling the Save Function
ExcelApp.put_DisplayAlerts( TRUE);

HTH

Thierry


这篇关于无需询问即可保存excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆