[英]how do i save a excel spreadsheet after editing it in access 2007 in VBA
I am trying to have Access 2007 open an Excel spreadsheet, add data to the cells, and then save the spreadsheet.我试图让 Access 2007 打开 Excel 电子表格,将数据添加到单元格,然后保存电子表格。 I have a button in an Access 2007 form which activates the following code.
我在 Access 2007 表单中有一个按钮,可以激活以下代码。 Here is what I have so far, but every "save command" doesn't work.
这是我到目前为止所拥有的,但每个“保存命令”都不起作用。 Does any one have any idea what to use?
有没有人知道要使用什么?
Private Sub buttonExcel_Click()
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
' Create a New Excel WorkBook
Set oExcel = CreateObject("Excel.Application")
' Optional, Open a current Workbook from a file directory
oExcel.Workbooks.Open ("Z:\08_Volume Management\ACCESS\EMAILTEMPLATES\test.xlsx")
' Make the Excel Workbook visible to the users
oExcel.Visible = True
' Define the Workbook from Excel
Set oBook = oExcel.ActiveWorkbook
' Define the Workskeet from the Workbook (1="Sheet1", 2="Sheet2", etc...)
Set oSheet = oBook.Worksheets(1)
' Write Data to the Worksheet (Block "A1" is the first row, first column)
oSheet.Range("A1").Value = "Hello World"
' Save the Excel Workbook
oExcel.SaveAs ("Z:\08_Volume Management\ACCESS\EMAILTEMPLATES\test.xlsx") ' DOESNT WORK
oExcel("Z:\08_Volume Management\ACCESS\EMAILTEMPLATES\test.xlsx").Save ' DOESNT WORK
oBook.SaveAs ("Z:\08_Volume Management\ACCESS\EMAILTEMPLATES\test.xlsx") ' DOESNT WORK
oBook("Z:\08_Volume Management\ACCESS\EMAILTEMPLATES\test.xlsx").Save ' DOESNT WORK
' Closes Excel as asks to save the Workbook
oExcel.Workbooks.Close
' Quit Excel
'oExcel.Quit
End Sub
Thanx!谢谢!
Private Sub buttonExcel_Click()
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Open ("Z:\08_Volume Management\" & _
"ACCESS\EMAILTEMPLATES\test.xlsx")
oExcel.Visible = True
Set oSheet = oBook.Worksheets(1)
oSheet.Range("A1").Value = "Hello World"
oBook.Save
oBook.Close
'or...
'oBook.Close True 'True = save changes
oExcel.Quit
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.