首页 > Excel专区 > Excel教程 >

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

Excel教程 2021-11-13 11:28:09

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

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 https://www.office9.cn. Some Rights Reserved.