我试图以编程方式向多个工作表中添加多个按钮,但是它仅适用于其中一个工作表(“ Sheet1”)。下面是我的代码,我想知道是否还有其他方法可以使我向Sheet2和其他任何按钮添加按钮。谢谢!
@Override
public void onCreate() {
super.onCreate();
mVolumeReceiver = new VolumeReceiver();
IntentFilter intentFilter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
registerReceiver(mVolumeReceiver, intentFilter);
}
private class VolumeReceiver extends BroadcastReceiver {
private final String TAG = VolumeReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
final String[] Modes = { "Unknown", "Silent", "Vibrate", "Normal" };
if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
int newMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1);
Log.i(TAG, "Ringer mode changed to: " + Modes[newMode + 1]);
}
}
}
结束子
答案 0 :(得分:1)
尝试
Sub test()
button_maker ThisWorkbook, Sheets(1)
button_maker ThisWorkbook, Sheets(2)
End Sub
Sub button_maker(wb As Workbook, Ws As Worksheet)
Dim r As Range
Dim Bt As Shape
Set Bt = Ws.Shapes.AddFormControl(xlButtonControl, 27, 30, 100, 20)
With Bt
.OnAction = "'" & wb.Name & "'" & "!" & "Button9_click"
.TextFrame.Characters.Text = "Input Sales"
End With
End Sub
答案 1 :(得分:0)
下面的代码将在活动工作簿的前三个工作表中添加一个按钮。
Option Explicit
Sub button_maker()
Dim Bt0 As Button
Dim Wb0 As Workbook: Set Wb0 = ActiveWorkbook
Dim i As Integer
For i = 1 To 3
Set Bt0 = Wb0.Sheets(i).Buttons.Add(27, 30, 100, 20)
Bt0.OnAction = ""
Bt0.Caption = "Input Sales"
'Bt0.Name = "" if you want to name it for future reference
Next i
End Sub
我不确定您的目标到底是什么,但是您可以使用此代码并使其适应您的需求。