EXCEL VBA 代码

记录单元格操作

1
2
Dim yz
Private Sub

自动保存

1
2
3
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
End Sub

捕获.png

自动备份

1
2
3
4
5
6
7
Private Sub Workbook_Open()
Dim wb As Workbook
Set wb = ThisWorkbook
t = Format(Now(), "hhmmss")
wb.SaveAs wb.Path & "\" & t & wb.Name

End Sub

打开工作簿时调用窗体

1
2
3
Private Sub Workbook_Open()
UserForm1.Show
End Sub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Dim MatLab As Object
Dim Result As String
Dim MReal(1, 3) As Double
Dim MImag(1, 3) As Double

MatLab = CreateObject("Matlab.Application")

'Call MATLAB function from VB
Result = MatLab.Execute("surf(peaks)")

'Execute simple computation
Result = MatLab.Execute("a = [1 2 3 4; 5 6 7 8]")
Result = MatLab.Execute("b = a + a ")

'Bring matrix b into VB program
MatLab.GetFullMatrix("b", "base", MReal, MImag)