AW: VBA Code mit VBA in Tabelle kopieren - Fehler?!
13.02.2009 11:20:00
Michel
Hallo,
ich benutze auch eine Tabelle in die ich Code hinein kopiere,
Es geht bei der Variante die ich habe NICHT mit dem Normelen CODE, sondern er muss als String vorliegen.
Eine andere Methode habe ich nicht gefunden, diesen Code hier benutze ich jedenfall schon viele Jahre.
Gruß
Michael
Hier mein Beispiel.
Der Code wird in "Open" Workbook eingefügt.
Er macht einfach nur die Aktuelle Woche Grau und den aktuellen Tag dunkelgrau.
Sub AddWorkbookEvent(neuName)
Dim lngStartLine As Long
Dim a As Integer, b As Integer
Application.VBE.MainWindow.Visible = False
a = Application.VBE.MainWindow.Height 'Fenstergröße merken
b = Application.VBE.MainWindow.Width ' Fenstergröße merken
Application.VBE.MainWindow.Height = 0
Application.VBE.MainWindow.Width = 0
With Workbooks(neuName).VBProject.VBComponents("DieseArbeitsmappe") _
.CodeModule
' Codeschablone einfügen
lngStartLine = .CreateEventProc("Open", "Workbook") + 1
Application.VBE.MainWindow.Visible = False
' Code in Ereignis-Prozedur einfügen
.InsertLines lngStartLine, _
"Dim i, spalte, jetztwoche, woche, wt As Single" & Chr$(13) _
& "Dim aktuelldatum As Date" & Chr$(13) _
& "Application.ScreenUpdating = False" & Chr$(13) _
& "Application.Calculation = xlManual" & Chr$(13) _
& "ActiveWorkbook.Colors(15) = RGB(210, 210, 210)" & Chr$(13) _
& "ActiveWorkbook.Colors(16) = RGB(180, 180, 180)" & Chr$(13) _
& "'For i = 4 To 100" & Chr$(13) _
& "'Columns(i).Interior.ColorIndex = 2" & Chr$(13) _
& "'Next i" & Chr$(13) _
& "spalte = 4" & Chr$(13) _
& " Do" & Chr$(13) _
& " aktuelldatum = Cells(4, spalte):wt = Weekday(aktuelldatum)" & Chr$(13) _
& " jetztwoche = DatePart(""ww"", Date, vbMonday, vbFirstFourDays)" & Chr$(13) _
& " woche = DatePart(""ww"", aktuelldatum, vbMonday, vbFirstFourDays)" & Chr$(13) _
& " If jetztwoche = woche And wt > 1 And wt 1 And wt Date + 5 Or spalte > 200 Or jetztwoche