如何在Excel VBA中创建通用组合框填充例程?

时间:2017-09-30 18:13:20

标签: excel vba excel-vba

我想在Microsoft Visual Basic for Application 7.1中使用通用方法填充组合框。

我尝试使用<!DOCTYPE html> <html lang="{{ app()->getLocale() }}"> <head> <title>{{ config('app.name') }} - Login</title> <link rel="stylesheet" href="assets/public/1.0/frontend/css/bulma.css?id={{ time() }}" type="text/css"> <link rel="stylesheet" href="assets/public/1.0/frontend/css/override.css?id={{ time() }}" type="text/css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> </head> <body class="inside"> <section class="hero is-danger inside-header"> <div class="hero-body"> <div class="container"> <div class="columns is-vcentered"> <div class="column is-5"> <p class="title header-title">Introducing {{ config('app.name') }}</p> <p class="subtitle">Interacting with others...</p> </div> <div class="column is-3"></div> <div class="column is-4"> <a class="button is-danger is-large is-disabled join-game-button"> <i class="fa fa-sign-in"></i> &nbsp;&nbsp;Join Game </a> <a class="button is-success is-large is-disabled users-online-button"> <i class="fa fa-users"></i> &nbsp;&nbsp;10 </a> <br><br> <a class="button is-success is-large is-disabled platform-button">Platform: Closed Beta</a> </div> </div> </div> </div> <div class="hero-foot"> <div class="container"> <nav class="tabs is-boxed"> <ul> <li class="is-active"> <a href="/documentation/overview/start/"> <i class="fa fa-user"></i> &nbsp;&nbsp;{{ Auth::user()->username }} </a> </li> <li> <a href="http://bulma.io/documentation/modifiers/syntax"> <i class="fa fa-university"></i> &nbsp;&nbsp;Business </a> </li> <li> <a href="http://bulma.io/documentation/columns/basics"> <i class="fa fa-user-secret"></i> &nbsp;&nbsp;Gangs </a> </li> <li> <a href="http://bulma.io/documentation/elements/box/"> <i class="fa fa-users"></i> &nbsp;&nbsp;Community </a> </li> <li> <a href="http://bulma.io/documentation/components/breadcrumb/"> <i class="fa fa-shopping-cart"></i> &nbsp;&nbsp;Store </a> </li> </ul> </nav> </div> </div> </section> <nav class="navbar has-shadow"> <div class="container"> <div class="navbar-tabs"> <a class="navbar-item is-tab is-active" href="http://bulma.io/documentation/overview/start/">Home</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/start/">Profile</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/customize/">Education</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/classes/">Skills</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/modular/">Housing</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/modular/">Security</a> </div> </div> </nav> <div class="container holorp-container-fixed"> <br> <div class="columns is-desktop"> <div class="column is-8"> <div class="message is-danger"> <div class="message-body"> <p>not sure what can even go here...</p> </div> </div> </div> <div class="column is-4"> <div class="message is-success"> <p class="message-header">Change Log <span class="is-pulled-right"><i class="fa fa-user"></i></span></p> <div class="message-body"> <span class="tag is-dark">26/09/17</span> &nbsp;&nbsp;<code>Updates the platform with a fresh design</code><br> <span class="tag is-dark">26/09/17</span> &nbsp;&nbsp;<code>Upgraded from Laravel 5.4 to 5.5</code><br> <span class="tag is-dark">26/09/17</span> &nbsp;&nbsp;<code>Added core features to the admin panel</code><br> <span class="tag is-dark">26/09/17</span> &nbsp;&nbsp;<code>Did something, can't even remember</code><br> <br> <p><a class="modal-button" data-target="#modal-forgotPassword" id="forgot-pw-modal">View all recent changes</a></p> </div> </div> </div> </div> </div> </body> 将控制参数转换为comboBox,但Excel不识别此功能。

如何以通用方式填充comboBox?

1 个答案:

答案 0 :(得分:1)

最简单的方法是通过ComboBox的名称。您无需将control转换为comboBox

Public Sub FillComboBox(UserForm As UserForm, cbName As String, column As String, startRow As Integer)
    Dim dataSheet As Worksheet
    Dim Count As Integer
    Set dataSheet = Worksheets("yourWorksheetName")

    Count = WorksheetFunction.CountA(dataSheet.Range(column & startRow & ":" & column & "10000")) - 1
    UserForm.Controls(cbName).List = dataSheet.Range(column & startRow & ":" & column & startRow + Count).value
End Sub

您的UserForm中的调用或任何地方的调用:

FillComboBox Me, Me.cbMyComboBox.name, "A", 1