首页 > Excel专区 > Excel函数 >

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

Excel函数 2023-01-13

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

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


Copyright © 2016-2023 office学习教程网 office.tqzw.net.cn. All Rights Reserved.