excel打开和关闭光驱的宏代码
- 2023-02-22
- 来源/作者: Wps Office教程网/ 菜鸟图库
- 112 次浏览
用下面的宏代码可以打开或关闭电脑中默认的光驱。方法是:
1.按Alt+F11打开VBA编辑器。
2.在代码窗口中输入下列代码:
Private Declare Sub mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, _
ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, _
ByVal hwndCallback As Long)
Sub OpenDefaultCDDVD()
‘打开光驱
mciSendStringA "Set CDAudio Door Open", 0&, 0, 0
End Sub
Sub CloseDefaultCDDVD()
‘关闭光驱
mciSendStringA "Set CDAudio Door Closed", 0&, 0, 0
End Sub