使用组合框删除工作表

时间:2015-08-20 09:52:04

标签: excel vba excel-vba

您好我一直在使用组合框删除工作表的代码,但我似乎无法运行它。我已经使用deletesheet子来调用userform,以便显示组合框,我可以选择和删除工作表。但是我在工作表上遇到类型不匹配错误(a)。删除(我已经把星号作为参考目的而没有那些运行程序)

 Private Sub setUserForm()
    With UserForm1
        .Height = 50:   .Width = 111
        .Caption = " Delete Sheets"
        With .ComboBox1
            .BackColor = RGB(240, 250, 255)
            .ControlTipText = "Select Sheet"
            .Height = 17:   .Width = UserForm1.Width - 15
            .Top = 7:       .Left = 7:  .ListRows = 22
            .MatchEntry = fmMatchEntryFirstLetter   '0
        End With
        .Show
    End With
End Sub


Sub deletesheet()
    Dim a As String  'This is changed
    Dim cmb As ComboBox
    Dim ws As Worksheet
    Set cmb = UserForm1.ComboBox1
    cmb.Clear
      For Each ws In Worksheets
        If ws.Visible Then cmb.AddItem ws.Name

        Next

    a = UserForm1.ComboBox1.Text   'This is changed
    *Worksheets(a).delete*
       cmb.ListIndex = 0
         setUserForm
End Sub

2 个答案:

答案 0 :(得分:0)

你应该使用

a = UserForm1.ComboBox1.Text

答案 1 :(得分:0)

将您的代码更改为以下内容:

document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);               
function onDeviceReady(){
    intel.xdk.device.setRotateOrientation('landscape');
    console.log('heyy');
    intel.xdk.device.hideSplashScreen();   
}        

这些更改是必需的,因为您已使用作为字符串的工作表名称填充ComboBox。然后,ComboBox1.Text将返回所选的特定字符串,因此必须将其存储在字符串变量