Wanneer CANCEL stopt de macro in Dialogbox

  • Onderwerp starter Onderwerp starter vovo
  • Startdatum Startdatum
Status
Niet open voor verdere reacties.

vovo

Gebruiker
Lid geworden
2 dec 2009
Berichten
98
Hallo beste forummers,

had het eerst op andere manier proberen te posten, echter er kwam geen reactie :confused:

Dus probeer ik het nu opnieuw, en by the way ondertussen heb ik al één en ander gevonden, maar nog niet alles.

Met welke code zeg je in VBA dat wanneer je op CANCEL drukt in een dialogbox (ipv OK) dat de macro dan gewoon mag stoppen zonder wijzigingen aan te brengen ?

Dit is alvast de comlete macro :

Code:
Sub Bonieuweklant()

Application.Goto Reference:="R1C1"
DialogSheets("dialog2").Show
Sheets("CUSTOMERS").Select
'code invoegen wanneer cancel, macro stopt ?
'colonne B
Application.Goto Reference:="R2500C2"
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select

'Nr sap
ActiveCell.FormulaR1C1 = DialogSheets("dialog2").EditBoxes("Edit Box 6").Caption
DialogSheets("dialog2").EditBoxes("Edit Box 6").Caption = ""
'Colonne C : merk
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
If DialogSheets("dialog2").OptionButtons("option button 19").Value = 1 Then
ActiveCell.FormulaR1C1 = "Glasurit"
End If
If DialogSheets("dialog2").OptionButtons("option button 20").Value = 1 Then
ActiveCell.FormulaR1C1 = "RM"
End If

'Colonne D : naam
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = DialogSheets("dialog2").EditBoxes("Edit Box 11").Caption
DialogSheets("dialog2").EditBoxes("Edit Box 11").Caption = ""

'Colonne E : n° adres
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = DialogSheets("dialog2").EditBoxes("Edit Box 13").Caption
DialogSheets("dialog2").EditBoxes("Edit Box 13").Caption = ""


' Colonne F : huisnr
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = DialogSheets("dialog2").EditBoxes("Edit Box 14").Caption
DialogSheets("dialog2").EditBoxes("Edit Box 14").Caption = ""


'Colonne G : PC
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = DialogSheets("dialog2").EditBoxes("Edit Box 16").Caption
DialogSheets("dialog2").EditBoxes("Edit Box 16").Caption = ""

'Colonne H : Plaats
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = DialogSheets("dialog2").EditBoxes("Edit Box 17").Caption
DialogSheets("dialog2").EditBoxes("Edit Box 17").Caption = ""

'Colonne I : Taalcode
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
If DialogSheets("dialog2").OptionButtons("option button 8").Value = 1 Then
ActiveCell.FormulaR1C1 = "FR"
End If
If DialogSheets("dialog2").OptionButtons("option button 9").Value = 1 Then
ActiveCell.FormulaR1C1 = "NL"
End If
ActiveCell.Offset(0, 1).Range("A1").Select
'insert


Dim diag As Object
Dim mydrop As Object

Set diag = DialogSheets("Dialog2")
Set mydrop = diag.DropDowns("Drop Down 27")


'Insert data into Drop Down
myarray = Array("BAERT", "BERTHE", "DEGUEL", "DEVILLE", "DIRECTIE", "DOCLO", "GRAULICH", "INSLEGERS", "JABON", "JAECQUES", "LEHMANN", "LODEWIJCKX", "MAES", "NESCA", "OOMS", "PEETERS", "RATY", "SIMUL", "STAELENS", "VAN VAERENBERGH", "VANDERLINDEN", "VANHAMME", "VERELST", "VERHAEGHE", "VERWACHT", "VIDO")

For x = 0 To 26
Next x
Sheets("Sales").Select
Range("F1").Select
ActiveWindow.SmallScroll Down:=-9
ActiveCell.FormulaR1C1 = "=VLOOKUP(R1C9,C3:C4,2,0)"
Range("F1").Select
Selection.Copy
Sheets("CUSTOMERS").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False


'end insert
' message box

'nog aanvullen !
' end message box

'Einde en sorteren
Application.Goto Reference:="R1C2:R5000C10"
Selection.Sort Key1:=Range("d2"), Order1:=xlAscending, Key2:=Range _
("G2"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
Range("B2").Select
Application.Goto Reference:="R2500C2"
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Sheets("BO").Select


End Sub
Code:
 
if "cancel" then exit sub

je moet wel ergens afvangen dat de cancel button gedrukt wordt

Ron
 
Vervang je rode regel door het volgende:

Code:
    If MsgBox("Doorgaan?", vbOKCancel) = vbCancel Then
        Exit Sub
    End If
 
Vervang je rode regel door het volgende:

Code:
    If MsgBox("Doorgaan?", vbOKCancel) = vbCancel Then
        Exit Sub
    End If

En zo eenvoudig kan het zijn !!! De locatie nog klein beetje aangepast en werkt prima !

Bedankt voor jullie snelle reactie !
 
Status
Niet open voor verdere reacties.

Nieuwste berichten

Terug
Bovenaan Onderaan