excel打开和关闭光驱的宏代码

来源:互联网 时间:2016-01-03

用下面的宏代码可以打开或关闭电脑中默认的光驱。方法是:

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

相关阅读:
Top