我想要一个按钮,当单击该按钮时,将数据从“field1”和“field2”复制到 Excel 电子表格到“field 3”和“field 4”并打印结果。
基本上,一旦有人下订单,我点击“付费”按钮,它就会将信息推送到模板中并打印。
The following code should get you started. The Excel template OrderSheet.xltx
has two single-cell Named Ranges: field3
and field4
. The rest should be pretty self-explanatory.
Private Sub cmdPlaceOrder_Click()
Dim objExcel As Object '' Excel.Application
Dim objSheet As Object '' Excel.Worksheet
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add "C:\Users\Public\OrderSheet.xltx"
objExcel.Range("field3").Value = Me.txtField1.Value
objExcel.Range("field4").Value = Me.txtField2.Value
Set objSheet = objExcel.ActiveSheet
objSheet.PrintOut
Set objSheet = Nothing
objExcel.ActiveWorkbook.Close False '' save changes = No
objExcel.Quit
Set objExcel = Nothing
End Sub