2010-10-13 132 views
1

我遇到以下困難:Excel導出爲Word(VBA):問題與循環

我想要將數據從Excel工作表導出到Word文檔。它的代碼工作,但問題是特定的代碼塊需要重複。這就是它錯了。

這是代碼的摘錄:

 Voortgang: 



If Controle1 = True Then 
      GoTo OpmaakKatern2 


    End If 
    If Controle2 = True Then 
     GoTo OpmaakKatern3 

    End If 







OpmaakKatern1: 
       If Datum1 = Empty Then 
         Controle1 = False 
         GoTo Eindsorteren 
       Else: 
        Controle1 = True 
       End If 
       .TypeParagraph 'Hier start katern1 
       .TypeParagraph 
       .Font.Size = 12 
       .Font.Bold = True 
       .Font.Underline = True 
       .TypeText Text:=Katern1  'Hier staat de naam van de katern 
       .Font.Bold = False 
       .Font.Underline = False 
       .TypeParagraph 
       .Font.Size = 10 
       .Font.Underline = True 
       .TypeText Text:="Datum:" 'Hier komt de gesorteerde datum, in te lezen als variabele 
       .Font.Underline = False 
       .TypeText Text:=" " & Datum1 'Hier komt de gesorteerde datum, in te lezen als variabele (aanhalingstekens verwijderen voor de variabele) 
       .TypeParagraph 
       .Font.Underline = True 
       .TypeText Text:="Gerealiseerde leerplandoelstellingen:" 
       .Font.Underline = False 
       If Katern1 = "Een nieuwe start" Then 
        GoTo Invulling_EenNieuweStart 
       ElseIf Katern1 = "Alles heeft zijn tijd" Then 
        GoTo Invulling_AllesHeeftZijnTijd 
       ElseIf Katern1 = "De wereld aan je voeten" Then 
        GoTo Invulling_DeWereldAanJeVoeten 
       ElseIf Katern1 = "Een levend boek" Then 
        GoTo Invulling_EenLevendBoek 
       ElseIf Katern1 = "Drempels" Then 
        GoTo Invulling_Drempels 
       ElseIf Katern1 = "Kerstmis" Then 
        GoTo Invulling_Kerstmis 
       ElseIf Katern1 = "Confituur of choco" Then 
        GoTo Invulling_ConfituurOfChoco 
       ElseIf Katern1 = "Hoe groot is de hemel?" Then 
        GoTo Invulling_HoeGrootIsDeHemel 
       ElseIf Katern1 = "Ongelovige Thomas" Then 
        GoTo Invulling_OngelovigeThomas 
       ElseIf Katern1 = "Feesten" Then 
        GoTo Invulling_Feesten 
       ElseIf Katern1 = "Er is er één jarig!" Then 
        GoTo Invulling_ErIsErEénJarig 
       ElseIf Katern1 = "Eén van hart" Then 
        GoTo Invulling_EénVanHart 
       ElseIf Katern1 = "Ervoor gaan" Then 
        GoTo Invulling_ErvoorGaan 
       ElseIf Katern1 = "Groen gras" Then 
        GoTo Invulling_GroenGras 
       ElseIf Katern1 = "RELatie" Then 
        GoTo Invulling_RELatie 
       ElseIf Katern1 = "Vele plaatjes" Then 
        GoTo Invulling_VelePlaatjes 
       ElseIf Katern1 = "Iedereen fan" Then 
        GoTo Invulling_IedereenFan 
       ElseIf Katern1 = "Schattenjacht" Then 
        GoTo Invulling_Schattenjacht 
       ElseIf Katern1 = "Lichtbakens" Then 
        GoTo Invulling_Lichtbakens 
       ElseIf Katern1 = "Rijke Luis" Then 
        GoTo Invulling_RijkeLuis 
       ElseIf Katern1 = "Hemel op aarde" Then 
        GoTo Invulling_HemelOpAarde 
       ElseIf Katern1 = "Op bezoek" Then 
        GoTo Invulling_OpBezoek 
       End If 

,這是一個Invulling_塊的例子:

Invulling_ErIsErEénJarig: 


         If Worksheets("Theo").Rij12_4.Value = True Then 
          .TypeParagraph 
          .TypeText Text:=Rij12 
         End If 
         If Worksheets("Theo").Rij13_4.Value = True Then 
          .TypeParagraph 
          .TypeText Text:=Rij13 
         End If 
         If Worksheets("Theo").Rij14_4.Value = True Then 
          .TypeParagraph 
          .TypeText Text:=Rij14 
         End If 
         If Worksheets("Theo").Rij15_3.Value = True Then 
          .TypeParagraph 
          .TypeText Text:=Rij15 
         End If 
         If Worksheets("Theo").Rij20_6.Value = True Then 
          .TypeParagraph 
          .TypeText Text:=Rij20 
         End If 
         If Worksheets("Theo").Rij22_5.Value = True Then 
          .TypeParagraph 
          .TypeText Text:=Rij22 
         End If 
         If Worksheets("Theo").Rij25_4.Value = True Then 
          .TypeParagraph 
          .TypeText Text:=Rij25 
         End If 
         If Worksheets("Theo").Rij28_4.Value = True Then 
          .TypeParagraph 
          .TypeText Text:=Rij28 
         End If 
         GoTo Voortgang 

這是它應該是如何工作的: 首先BLOK「OpmaakKatern1 「運行,在這個程序塊中,某些內容被選中ip(」Invulling _...「),並且在這些Invulling_-blocks結尾處有一個GoTo命令,它將代碼發送到控制器(」 Voortgang:「,它應該檢查哪個」OpmaakKatern ..「已經被執行。) 但這不起作用。它不斷重複第二個OpmaakKatern,而不是搬到第三個OpmaakKatern。

有沒有人可以幫助我呢?

非常感謝!

親切的問候, 馬克

+0

http://en.wikipedia.org/wiki/Array_data_structure – 2010-10-13 19:09:49

回答

0

你確定你在OpmaakKatern2塊設置Controle2爲True有一條線的地方?

Controle2 = True