VBA工作簿_打开不工作

时间:2017-03-24 15:09:09

标签: excel vba excel-vba

我正在努力使用以下代码。首先,当我打开工作簿时它似乎没有运行。

我的第二个问题是当我通过VBA手动运行此代码时(如在F8中)。当它到达Listindex / Listcount命令时,它会在尝试根据用户在组合框中的选择运行单独的代码时失败。这是因为它试图运行变量'Select Server',这显然不是服务器。但是在打开工作簿时我不希望它运行任何东西我只想要“选择服务器”的简洁指令。

Option Explicit

Private Sub Workbook_Open()

With Application
    '.Calculation = xlManual
    .EnableEvents = False
    .ScreenUpdating = False
End With

        Sheets("Data Summary").CB_Server.AddItem "Select Server"
        Sheets("Data Summary").CB_Server.AddItem "UK-SQL-Z001"
        Sheets("Data Summary").CB_Server.AddItem "UK-SQL-z002"
        Sheets("Data Summary").CB_Server.ListIndex = Sheets("Data Summary").CB_Server.ListCount - 3


        Sheets("Data Summary").CB_DB.AddItem "Select DB"
        Sheets("Data Summary").CB_DB.ListIndex = Sheets("Data Summary").CB_DB.ListCount - 1

        With Sheets("Data Summary").CB_Portfolio
        .AddItem
        .List(0, 0) = "Select Portfolio"
        .List(0, 1) = "Select Portfolio"
        End With

        Sheets("Data Summary").CB_CCY.AddItem "GBP"
        Sheets("Data Summary").CB_CCY.AddItem "EUR"
        Sheets("Data Summary").CB_CCY.AddItem "USD"
        Sheets("Data Summary").CB_CCY.ListIndex = Sheets("Data Summary").CB_CCY.ListCount - 3

Sheets("Data Summary").Range("D11:H23").Cells.ClearContents

Sheets("Data Sheet").Range("B2:G10").Cells.ClearContents

'Restore the settings.
With Application
    .Calculation = xlAutomatic
    .EnableEvents = True
    .ScreenUpdating = True
End With

End Sub

我做错了什么!提前致谢

0 个答案:

没有答案