Opening .xlsx file and changing a form control label using a .xlsm workbook

MistakesWereMade

Board Regular
Joined
May 22, 2019
Messages
103
I have a workbook that opens another workbook. Can I control the caption on a label using a separate workbook that is running all my code? Below is my code... but I have an error in the last line.

Code:
Private Sub CommandButton1_Click()


    Dim Wbk1 As Workbook
    Dim Pth1 As String
    Dim OpeningVar1 As String
    
    Pth1 = Environ("Userprofile") & "\Desktop\HT\"


    OpeningVar1 = "36MN.xlsx"
    
    Set Wbk1 = Workbooks.Open(Pth1 & OpeningVar1)


    If Application.CommandBars("Ribbon").Height <= 150 Then
        CommandBars.ExecuteMso "HideRibbon"
    End If


    Workbook("36MN.xlsx").Label3.Caption = Empl
    
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this

Change Sheet1 by the name of your sheet
Code:
Workbooks("36MN.xlsx").Sheets("[COLOR=#ff0000]Sheet1[/COLOR]").Label3.Caption = Empl
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top