Excel /如何连接不同工作表上的按钮

时间:2017-08-07 09:47:09

标签: excel vba excel-vba

my first button (Schaltfläche 83) 我的第一个按钮(Schaltfläche83)

enter image description here 我要激活的其他按钮vom“Hirata Bestellformular” 第一个选项:顶部蓝色选项 第二个选项:大选项(activexelement)

我想激活另一个工作表中的一个按钮,因为我想直接从“Hirata Bestellformular”在工作表“Teileliste”上执行下面的代码。我怎么能做到这一点?

Sub Teileliste_generieren()

'高级过滤器

Sheets("Hirata Bestellformular").Range("Tabelle3[[#Headers],[#Data]]"). _
    AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("B50:B51"), _
    CopyToRange:=Range("B54:B55"), Unique:=False

    Range("B5").Select
ActiveCell.FormulaR1C1 = _
    "=IFERROR(LEFT(R[50]C,FIND(CHAR(10),R[50]C)-1),R[50]C)"
Range("B6").Select
ActiveCell.FormulaR1C1 = _
    "=IFERROR(LEFT(R[50]C,FIND(CHAR(10),R[50]C)-1),R[50]C)"
Range("B5:B6").Select
Selection.AutoFill Destination:=Range("B5:B26"), Type:=xlFillDefault
Range("B5:B26").Select
Range("D22").Select

'formatierung tabelle

Range("B3").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 16763955
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
Range("B4").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternThemeColor = xlThemeColorAccent3
    .Color = 16777215
    .TintAndShade = 0
    .PatternTintAndShade = 0.799981688894314
End With
Range("B5").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 9868950
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
Range("B6").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 15395562
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
Range("B5:B6").Select
Selection.AutoFill Destination:=Range("B5:B26"), Type:=xlFillDefault
Range("B5:B26").Select
Range("D20").Select

'Wenn 0 blank

Range("B5:B26").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
    Formula1:="=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("C22").Select

' Exportieren

    ThisWorkbook.Sheets("Teileliste").Copy

Application.GetSaveAsFilename

End Sub

3 个答案:

答案 0 :(得分:0)

快速提示:

您可以右键单击按钮Schaltfläche83并为其指定一个宏。因此,在您的情况下,您可以右键单击 - >分配宏 - >选择

Teileliste_generieren()

如果您的代码可以处理在不同工作表上的调用,那么它将起作用。

//来自我的iPhone

答案 1 :(得分:0)

我可以试试。 :)

如果我了解您,您希望能够从Teileliste generierenHirata Bestellformular。这意味着您仍然希望按钮Schaltfläche 83执行与Teileliste generieren相同的操作,但您不想切换工作表以按下按钮?

然后我相信您的问题出在您的Range.Select声明中。

在Excels VBA对象模型中,如果您从Range("B50:B51").Select表单中调用Teileliste,则会自动在Teileliste - 表格中选择该范围。如果从Hirata Bestellformular开始,则会从Range("B50:B51")中选择Hirata Bestellformular

这意味着:如果您将所有Range("...").Select更改为Worksheets("Teileliste").Range("...").Select

工作

这与Excel VBA Object Model.

有关

我非常确定应该这样做,但这取决于代码的放置位置(在特定工作表内或模块中)。尝试替换Range.Selects并查看是否有帮助。 :)

答案 2 :(得分:0)

Sub Teileliste_generieren2()

'高级过滤器

Sheets("Hirata Bestellformular").Range("Tabelle3[[#Headers],[#Data]]"). _
    AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Worksheets("Teileliste").Range("B50:B51"), _
    CopyToRange:=Worksheets("Teileliste").Range("B54:B55"), Unique:=False

    Worksheets("Teileliste").Range("B5").Select
ActiveCell.FormulaR1C1 = _
    "=IFERROR(LEFT(R[50]C,FIND(CHAR(10),R[50]C)-1),R[50]C)"
Worksheets("Teileliste").Range("B6").Select
ActiveCell.FormulaR1C1 = _
    "=IFERROR(LEFT(R[50]C,FIND(CHAR(10),R[50]C)-1),R[50]C)"
Worksheets("Teileliste").Range("B5:B6").Select
Selection.AutoFill Destination:=Worksheets("Teileliste").Range("B5:B26"), Type:=xlFillDefault
Worksheets("Teileliste").Range("B5:B26").Select
Worksheets("Teileliste").Range("D22").Select

'formatierung tabelle

    Worksheets("Teileliste").Range("B5").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark2
    .TintAndShade = -0.249977111117893
    .PatternTintAndShade = 0
End With
Worksheets("Teileliste").Range("B6").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent4
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
Worksheets("Teileliste").Range("B5:B6").Select
Selection.AutoFill Destination:=Worksheets("Teileliste").Range("B5:B26"), Type:=xlFillDefault
Worksheets("Teileliste").Range("B5:B26").Select
Worksheets("Teileliste").Range("C18").Select

'Wenn 0 blank

Worksheets("Teileliste").Range("B5:B26").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
    Formula1:="=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Worksheets("Teileliste").Range("C22").Select

' Exportieren

    ThisWorkbook.Sheets("Teileliste").Copy

Application.GetSaveAsFilename

End Sub

我就像你说的那样在任何地方更换它,如果我从“Teileliste”中激活了makro,它就有效但是当我从“Hiraa Bestellformular”中激活它时出现错误说:Error1004他选择 - 范围对象的方法不能执行:/另一个建议?:)