Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

[EXCEL VBA] Automatiseringsfout -2147467259

Pagina: 1
Acties:

  • AcidBanger
  • Registratie: Maart 2008
  • Laatst online: 17-11 09:39
Goedemiddag Tweakers ! :)

Ik zit weer is klem. Sinds een paar dagen hebben we een probleem met onze mooi excel sheet.
We krijgen nu als we de code uitvoeren een error.
Automatiseringsfout -2147467259

Ik heb code helemaal zitten napluizen maar komt er niet uit.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
Sub UserForm_Initialize()
  
  'comboboxen invullen
  
    ComboBox1.List = Array("Testpersoon 1", "Testpersoon 2")
    ComboBox2.List = Array("24 uur", "1-2 werkdagen", "3-5 werkdagen", "1 week", "2-3 weken", "Onbekend")
    ComboBox3.List = Array("Vooruitbetaling", "Op rekening 14 dagen", "Op rekening 30 dagen")
    

End Sub

Private Sub CommandButton1_Click()

'checken of alle boxen zijn ingevuld.

If Trim(Me.TextBoxNaam.Value) = "" Then
Me.TextBoxNaam.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

If Trim(Me.TextBoxDebiteur.Value) = "" Then
Me.TextBoxDebiteur.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

If Trim(Me.TextBoxKenmerk.Value) = "" Then
Me.TextBoxKenmerk.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

If Trim(Me.TextBoxContactpersoon.Value) = "" Then
Me.TextBoxContactpersoon.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

If Trim(Me.ComboBox1.Value) = "" Then
Me.ComboBox1.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

If Trim(Me.ComboBox2.Value) = "" Then
Me.ComboBox2.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

If Trim(Me.ComboBox3.Value) = "" Then
Me.ComboBox3.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

If Trim(Me.TextBox209.Value) = "" Then
Me.TextBox209.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

If Trim(Me.TextBox210.Value) = "" Then
Me.TextBox210.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If


'Standaard data kopieëren naar excel

Range("C8") = TextBoxNaam
Range("C7") = TextBoxDebiteur
Range("C12") = TextBoxKenmerk
Range("C11") = TextBoxContactpersoon
Range("I13") = ComboBox1
Range("C35") = ComboBox2
Range("C36") = ComboBox3
Range("C9") = TextBox209
Range("C10") = TextBox210

'Artikelen kopieëren naar excel
Range("A17") = TextBox5
Range("B17") = TextBox6
Range("G17") = TextBox7
Range("J17") = TextBox8

Range("A18") = TextBox9
Range("B18") = TextBox10
Range("G18") = TextBox11
Range("J18") = TextBox12

Range("A19") = TextBox13
Range("B19") = TextBox14
Range("G19") = TextBox15
Range("J19") = TextBox16

Range("A20") = TextBox17
Range("B20") = TextBox18
Range("G20") = TextBox19
Range("J20") = TextBox20

Range("A21") = TextBox21
Range("B21") = TextBox22
Range("G21") = TextBox23
Range("J21") = TextBox24

Range("A22") = TextBox25
Range("B22") = TextBox26
Range("G22") = TextBox27
Range("J22") = TextBox28

Range("A23") = TextBox29
Range("B23") = TextBox30
Range("G23") = TextBox31
Range("J23") = TextBox32

Range("A24") = TextBox33
Range("B24") = TextBox34
Range("G24") = TextBox35
Range("J24") = TextBox36

Range("A25") = TextBox37
Range("B25") = TextBox38
Range("G25") = TextBox39
Range("J25") = TextBox40

Range("A26") = TextBox41
Range("B26") = TextBox42
Range("G26") = TextBox43
Range("J26") = TextBox44

Range("A27") = TextBox45
Range("B27") = TextBox46
Range("G27") = TextBox47
Range("J27") = TextBox48

Range("A28") = TextBox49
Range("B28") = TextBox50
Range("G28") = TextBox51
Range("J28") = TextBox52

Range("A29") = TextBox53
Range("B29") = TextBox54
Range("G29") = TextBox55
Range("J29") = TextBox56

Range("A30") = TextBox57
Range("B30") = TextBox58
Range("G30") = TextBox59
Range("J30") = TextBox60

Range("A31") = TextBox61
Range("B31") = TextBox62
Range("G31") = TextBox63
Range("J31") = TextBox64

Range("A32") = TextBox65
Range("B32") = TextBox66
Range("G32") = TextBox67
Range("J32") = TextBox68

Range("A33") = TextBox69
Range("B33") = TextBox70
Range("G33") = TextBox71
Range("J33") = TextBox72

'Artikelen tweede pagina kopieëren naar excel

Range("A59") = TextBox73
Range("B59") = TextBox74
Range("G59") = TextBox75
Range("J59") = TextBox76

Range("A60") = TextBox77
Range("B60") = TextBox78
Range("G60") = TextBox79
Range("J60") = TextBox80

Range("A61") = TextBox81
Range("B61") = TextBox82
Range("G61") = TextBox83
Range("J61") = TextBox84

Range("A62") = TextBox85
Range("B62") = TextBox86
Range("G62") = TextBox87
Range("J62") = TextBox88

Range("A63") = TextBox89
Range("B63") = TextBox90
Range("G63") = TextBox91
Range("J63") = TextBox92

Range("A64") = TextBox93
Range("B64") = TextBox94
Range("G64") = TextBox95
Range("J64") = TextBox96

Range("A65") = TextBox97
Range("B65") = TextBox98
Range("G65") = TextBox99
Range("J65") = TextBox100

Range("A66") = TextBox101
Range("B66") = TextBox102
Range("G66") = TextBox103
Range("J66") = TextBox104

Range("A67") = TextBox105
Range("B67") = TextBox106
Range("G67") = TextBox107
Range("J67") = TextBox108

Range("A68") = TextBox109
Range("B68") = TextBox110
Range("G68") = TextBox111
Range("J68") = TextBox112

Range("A69") = TextBox113
Range("B69") = TextBox114
Range("G69") = TextBox115
Range("J69") = TextBox116

Range("A70") = TextBox117
Range("B70") = TextBox118
Range("G70") = TextBox119
Range("J70") = TextBox120

Range("A71") = TextBox121
Range("B71") = TextBox122
Range("G71") = TextBox123
Range("J71") = TextBox124

Range("A72") = TextBox125
Range("B72") = TextBox126
Range("G72") = TextBox127
Range("J72") = TextBox128

Range("A73") = TextBox129
Range("B73") = TextBox130
Range("G73") = TextBox131
Range("J73") = TextBox132

Range("A74") = TextBox133
Range("B74") = TextBox134
Range("G74") = TextBox135
Range("J74") = TextBox136

Range("A75") = TextBox137
Range("B75") = TextBox138
Range("G75") = TextBox139
Range("J75") = TextBox140

'Artikelen derde pagina kopiëren naar excel

Range("A101") = TextBox141
Range("B101") = TextBox142
Range("G101") = TextBox143
Range("J101") = TextBox144

Range("A102") = TextBox145
Range("B102") = TextBox146
Range("G102") = TextBox147
Range("J102") = TextBox148

Range("A103") = TextBox149
Range("B103") = TextBox150
Range("G103") = TextBox151
Range("J103") = TextBox152

Range("A104") = TextBox153
Range("B104") = TextBox154
Range("G104") = TextBox155
Range("J104") = TextBox156

Range("A105") = TextBox157
Range("B105") = TextBox158
Range("G105") = TextBox159
Range("J105") = TextBox160

Range("A106") = TextBox161
Range("B106") = TextBox162
Range("G106") = TextBox163
Range("J106") = TextBox164


Range("A107") = TextBox165
Range("B107") = TextBox166
Range("G107") = TextBox167
Range("J107") = TextBox168

Range("A108") = TextBox169
Range("B108") = TextBox170
Range("G108") = TextBox171
Range("J108") = TextBox172


Range("A109") = TextBox173
Range("B109") = TextBox174
Range("G109") = TextBox175
Range("J109") = TextBox176


Range("A110") = TextBox177
Range("B110") = TextBox178
Range("G110") = TextBox179
Range("J110") = TextBox180

Range("A111") = TextBox181
Range("B111") = TextBox182
Range("G111") = TextBox183
Range("J111") = TextBox184

Range("A112") = TextBox185
Range("B112") = TextBox186
Range("G112") = TextBox187
Range("J112") = TextBox188

Range("A113") = TextBox189
Range("B113") = TextBox190
Range("G113") = TextBox191
Range("J113") = TextBox192

Range("A114") = TextBox193
Range("B114") = TextBox194
Range("G114") = TextBox195
Range("J114") = TextBox196

Range("A115") = TextBox197
Range("B115") = TextBox198
Range("G115") = TextBox199
Range("J115") = TextBox200

Range("A116") = TextBox201
Range("B116") = TextBox202
Range("G116") = TextBox203
Range("J116") = TextBox204

Range("A117") = TextBox205
Range("B117") = TextBox206
Range("G117") = TextBox207
Range("J117") = TextBox208

CellenLeegmaken

Unload Me



End Sub

Sub CellenLeegmaken()
For Each huidigecel In Range("A17:A33,J17:J33,A59:A75,J59:J75,A101:A117,A101:J117")
  If huidigecel.Value = "" Then
    huidigecel.Value = ""
  End If
Next
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub


Het laatste stukje code

code:
1
2
3
4
5
6
7
Sub CellenLeegmaken()
For Each huidigecel In Range("A17:A33,J17:J33,A59:A75,J59:J75,A101:A117,A101:J117")
  If huidigecel.Value = "" Then
    huidigecel.Value = ""
  End If
Next
End Sub


Is nodig om een #WAARDE error te voorkomen in de excel sheet zelf, het ziet er een beetje apart uit. Maar dan weten jullie waarom het erin zit :)

Maar zodra dit dus word uitgevoerd krijgen we gelijk automatiserings error en dan loopt excel compleet vast waardoor ik dus ook de foutopsoring niet kan aanklikken.

Ik hoop dat iemand een idee heeft ! :)

  • nescafe
  • Registratie: Januari 2001
  • Laatst online: 17:36
Zet een breakpoint binnen je sub CommandButton1_Click() en start de functionaliteit nogmaals.

Je kunt nu met F8 telkens een regel verder springen waardoor je vanzelf de fout tegenkomt.

Wat je kunt doen om 'snel' te vinden waar de crash (reproduceerbaar) optreedt, is het breakpoint eerst halverwege de sub te plaatsen. Gaat het dan nog goed, dan op 25% en anders op 75% van je code. Vanaf daar heb je een startpunt om door te steppen en de fout te vinden.

* Barca zweert ook bij fixedsys... althans bij mIRC de rest is comic sans


  • Witte
  • Registratie: Februari 2000
  • Laatst online: 15-10 13:46
Excel vindt Range("A1") niet leuk. Soms heeft Excel moeite met bepalen in welk werkblad hij deze cel moet vinden.
Je kan dit zo oplossen:
ActiveWorkbook.Sheets("blad1").Range etc.

Dan heb je alleen het probleem dat je je werkblad geen ander naampje mag geven.

Maar of dat het probleem is, weet ik niet. Ik zou inderdaad beginnen met een breakpoint en dan door je code stappen met F8.

Houdoe


  • rense
  • Registratie: Mei 2003
  • Laatst online: 15:09
Witte schreef op donderdag 20 augustus 2015 @ 11:30:
Excel vindt Range("A1") niet leuk. Soms heeft Excel moeite met bepalen in welk werkblad hij deze cel moet vinden.
Je kan dit zo oplossen:
ActiveWorkbook.Sheets("blad1").Range etc.

Dan heb je alleen het probleem dat je je werkblad geen ander naampje mag geven.
Of bovenstaande uitbreiden met:
ActiveWorkbook.Activesheet.Range

Ik definieer standaard aan het begin van alle scriptjes de activeworkbook en activeworksheet. Als een gebruiker heel actief switched tussen zijn WIndows wil de waarde van deze nog wel eens veranderen tijdens het uitvoeren van een lang script.

Dus zoiets als:
Dim wb as Workbook
Dim sh as Worksheet

Set wb = Activeworkbook
Set sh = wb.Activesheet

Daarna kun je dan verwijzen met sh.Range("A1").

  • Witte
  • Registratie: Februari 2000
  • Laatst online: 15-10 13:46
Dat kan natuurlijk, maar dan moet wél de juiste sheet 'active' zijn :) Daarom benoem ik hem met de naam. Nogmaals, de naam mag dan niet wijzigen. (of je moet de code ook wijzigen)

[ Voor 11% gewijzigd door Witte op 20-08-2015 11:45 ]

Houdoe


  • AcidBanger
  • Registratie: Maart 2008
  • Laatst online: 17-11 09:39
Ik weer nieuwe info dit probleem treed blijkbaar alleen op in office 2007 met office 2010 geen problemen.
Het vage is ook nog is dat ik het probleem niet heb zodra ik het ontwikkelaars scherm open houd.

Het rare is ook dat zodra ik een stukje in de code aanpas en save ook al is het maar dat ik 1 letter weghaal en weer terugplaats dan krijg ik geen foutmelding zolang ik de excelsheet open houd. Zodra ik hem 1 keer sluit en opnieuw open dat geeft hij weer de error zodra ik de code uitvoer.

  • nescafe
  • Registratie: Januari 2001
  • Laatst online: 17:36
.. okay, maar ik ben ook wel benieuwd wat het resultaat is van de aanpassing door Witte en rense geschetst :) Range kun je beter zo expliciet mogelijk aanroepen, kan me voorstellen dat het (afh. van het openstaande VBA-venster) al dan niet modal tonen van je userform invloed kan hebben op het resultaat van (Me.)Range ten opzichte van sh.Range.

Mocht dit niets uithalen, dan verdient het m.i. nog steeds de voorkeur om een debugbaar scenario te maken:
[list]
• Installeer MZ-Tools 3.0 (voor VBA)
• Voeg de error handler toe aan je sub CommandButton1_Click
• Voeg line numbers toe aan je sub CommandButton1_Click
• Sla het project op, sluit af, run (zonder VBA-venster te openen)


Mocht je geen MZ-Tools kunnen installeren, dan komt het handmatig hierop neer:

In de start van je sub:
Visual Basic:
1
On Error Goto eh


Aan het eind van je sub:
Visual Basic:
1
2
3
4
    Exit Sub

eh:
    MsgBox "Error in line " & Erl & ": " & Err.Description


Vervolgens moet je je lines handmatig nummeren, aangezien dit nog een tijdrovend werk is kun je dan 'slim' regels nummeren, bijv. voor de 1e procedure alle regels en vervolgens alleen de 1e regel.

Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1 If Trim(Me.TextBoxNaam.Value) = "" Then
2 Me.TextBoxNaam.SetFocus
3 MsgBox "Graag alles invullen !"

4 Exit Sub
5 End If

20 If Trim(Me.TextBoxDebiteur.Value) = "" Then
Me.TextBoxDebiteur.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

30 If Trim(Me.TextBoxKenmerk.Value) = "" Then
Me.TextBoxKenmerk.SetFocus
MsgBox "Graag alles invullen !"

Exit Sub
End If

* Barca zweert ook bij fixedsys... althans bij mIRC de rest is comic sans

Pagina: 1