首页 > Excel专区 > Excel函数 >

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

Excel函数 2022-02-13 20:34:39

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

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


标签: 代码光驱关闭打开excel函数

office教程网 Copyright © 2016-2020 http://www.office9.cn. Some Rights Reserved. 苏ICP备20040415号-9