Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

excel - Workbook_Open sub won't run when I open the workbook?

This program is supposed to create a button that the user can press to activate a different sub. From my searches online, it seems that the sub below should activate when opening up the workbook, but it's not?

What am I doing wrong?

Option Explicit
Private Sub Workbook_Open()
Dim btn As Button
Dim rng As Range
With Worksheets("Sheet1")
    Set rng = .Range("B2:C2")
        Set btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
    With btn
        .Caption = "To begin the program, please click this button"
        .AutoSize = True
        .OnAction = "TableCreation1"
    End With
End With
End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Make sure your Private Sub Workbook_Open() subroutine is pasted inside of the This Workbook object and not in a Module, Form, or Sheet object.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...