Consulting

Results 1 to 2 of 2

Thread: adding code in runtime

  1. #1
    VBAX Newbie
    Joined
    Jul 2008
    Posts
    1
    Location

    adding code in runtime

    Hello,

    When I try to add code in runtime after clicking a button, excel says it has come acros an error and it has to shut down.
    I'm using excel 2003 sp2
    and this is the code I'm using:


    [VBA] With Workbooks(BestandsNaam).VBProject.VBComponents("Blad2").CodeModule
    .InsertLines .CountOfLines + 1, "private Sub " + "bLeverantieToevoegen" + typenVerzameling(typenVuller) + "_click()"
    .InsertLines .CountOfLines + 1, " Sheets(""Algemeen"").Cells(1, 1).Value = ""Woning"" "
    .InsertLines .CountOfLines + 1, " Sheets(""Algemeen"").Cells(1, 2).Value = ""Type Woning leverantie"" "
    .InsertLines .CountOfLines + 1, " Sheets(""Algemeen"").Cells(1, 3).Value = ""Type Woning Uren"" "
    .InsertLines .CountOfLines + 1, " Sheets(""Algemeen"").Cells(1, 4).Value = " + """" + "Leverantie Details(Groep: " + groepNaam + ", Type: " + typeNaam + "(" + nummer + "))" + """"
    .InsertLines .CountOfLines + 1, " Sheets(""Algemeen"").Cells(1, 5).Value = " + """" + "Uren Details(Groep: " + groepNaam + ", Type: " + typeNaam + "(" + nummer + "))" + """"
    .InsertLines .CountOfLines + 1, " Load Selecteren"
    .InsertLines .CountOfLines + 1, " Selecteren.Show"
    .InsertLines .CountOfLines + 1, "End Sub" & Chr(13)
    End With
    [/VBA]

    Can anyone see what I'm doing wrong here?

    With Kind regards,
    Rob

    Edited by Aussiebear: To include code within the VBA Tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is difficult to envisgae what the final code is meant to look like, what is variables, what is text, but is this any better?

    [vba]

    With Workbooks(BestandsNaam).VBProject.VBComponents("Blad2").CodeModule
    .InsertLines .CountOfLines + 1, _
    "private Sub " & "bLeverantieToevoegen" & typenVerzameling(typenVuller) & "_click()" & vbNewLine & _
    " Sheets(""Algemeen"").Cells(1, 1).Value = ""Woning"" " & vbNewLine & _
    " Sheets(""Algemeen"").Cells(1, 2).Value = ""Type Woning leverantie"" " & vbNewLine & _
    " Sheets(""Algemeen"").Cells(1, 3).Value = ""Type Woning Uren"" " & vbNewLine & _
    " Sheets(""Algemeen"").Cells(1, 4).Value = " & """" & _
    "Leverantie Details(Groep: " & groepNaam & ", Type: " & _
    typeNaam & "(" & nummer & "))" & """" & vbNewLine & _
    " Sheets(""Algemeen"").Cells(1, 5).Value = " & """" & _
    "Uren Details(Groep: " & groepNaam & ", Type: " & _
    typeNaam & "(" & nummer & "))" & """" & vbNewLine & _
    " Load Selecteren" & vbNewLine & _
    " Selecteren.Show" & vbNewLine & _
    "End Sub" & vbCrLf
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •