Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 05-19-2016, 09:37 PM
gmayor's Avatar
gmayor gmayor is offline Update Userform  Captions, TextBoxes, Command buttons From Excel Windows 10 Update Userform  Captions, TextBoxes, Command buttons From Excel Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The short answer is yes you can do this, with a couple of provisos, and it will be faster from Excel. The first is that you should have the names of the command buttons in the first column and not merely numbers.

Command Button Caption
CommandButton1 Edit Text
CommandButton2 Add Column
CommandButton3 Delete Column
CommandButton4 Delete Table
CommandButton5 Font Resize

The second is that I would only do this if the names changed frequently (otherwise it is better to name the buttons either directly or in code). That being the case, you could use the following macro (in an ordinary module) to call the userform and name the buttons.

Code:
Option Explicit
Const strWorkbook As String = "C:\Path\Forums\buttons.xlsx" 'The workbook path
Const strSheet As String = "Sheet1"        'The name of the worksheet

Sub Example()
'Graham Mayor - www.gmayor.com
Dim oFrm As New UserForm1
Dim Arr() As Variant
Dim oCtrl As Control
Dim i As Long
    Arr = xlFillArray(strWorkbook, strSheet)
    With oFrm
        For i = 0 To UBound(Arr, 2)
            For Each oCtrl In .Controls
                If oCtrl.Name = Arr(0, i) Then
                    oCtrl.Caption = Arr(1, i)
                    Exit For
                End If
            Next oCtrl
        Next i
        .Show
    End With
lbl_Exit:
    Set oCtrl = Nothing
    Exit Sub
End Sub


Private Function xlFillArray(strWorkbook As String, _
                             strWorksheetName As String) As Variant
'Graham Mayor - www.gmayor.com
Dim RS As Object
Dim CN As Object
Dim iRows As Long

    strWorksheetName = strWorksheetName & "$]"
    Set CN = CreateObject("ADODB.Connection")
    CN.Open ConnectionString:="Provider=Microsoft.ACE.OLEDB.12.0;" & _
                              "Data Source=" & strWorkbook & ";" & _
                              "Extended Properties=""Excel 12.0 Xml;HDR=YES"";"

    Set RS = CreateObject("ADODB.Recordset")
    RS.Open "SELECT * FROM [" & strWorksheetName, CN, 2, 1

    With RS
        .MoveLast
        iRows = .RecordCount
        .MoveFirst
    End With
    xlFillArray = RS.GetRows(iRows)
    If RS.State = 1 Then RS.Close
    Set RS = Nothing
    If CN.State = 1 Then CN.Close
    Set CN = Nothing
lbl_Exit:
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Userform  Captions, TextBoxes, Command buttons From Excel Captions: Changing captions in Appendix update all captions carnestw Word 3 10-27-2015 12:34 PM
Can't update/refresh embedded Excel file with Power Point 2010 command button mt1013 PowerPoint 0 06-17-2015 05:18 AM
VBA Code in a UserForm module to delete a Command Button which opens the userform Simoninparis Word VBA 2 09-21-2014 03:50 AM
UserForm Search with multiple TextBoxes johndough Excel Programming 0 05-10-2014 12:11 PM
VBA code to update record in Access 2003 using Userform in Excel primmer3001 Excel Programming 0 08-29-2011 04:25 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft