AW: VBA Code in "DieseArbeitsmappe" extern ändern
10.05.2010 09:44:19
Kai
Ein Addin kommt auf Grund mangelnder Flexibilität und der häufigen Weitergabe der Dateien absolut nicht in Frage. Gedanken habe ich mir darum schon gemacht...
Luc, was genau meinst du mit Index? Sorry, aber ich stehe da gerade aufm Schlauch :)
@Ramses:
'LOAD
Private Sub CommandButton1_Click()
Dim Wkb As Workbook, Zielmappe As Workbook
Dim strPfad As String, strDatei As String, tabName As String
Dim abbruch As Integer
abbruch = 0
On Error GoTo Errorhandling:
Set Zielmappe = ThisWorkbook
tabName = ActiveSheet.Name
'Abort condition
Do While abbruch = 0
'Choose process
MsgBox "Load process folder. Press 'Cancel' when completed."
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select folder"
.ButtonName = "Choose folder..."
.InitialView = msoFileDialogViewList
If .Show = -1 Then
strPfad = .SelectedItems(1) & "\"
Else
strPfad = ""
End If
End With
If strPfad = "" Then
MsgBox ("Done")
abbruch = 1
GoTo AbortLoad
Else
'MsgBox strPfad
End If
'Load process
strDatei = Dir(strPfad & "*.xls", vbDirectory)
Do While strDatei ""
Set Wkb = Workbooks.Open(strPfad & strDatei, False, False)
Wkb.VBProject.VBComponents("DieseArbeitsmappe").CodeModule.AddFromFile ("C:\Dokumente und _
Einstellungen\kai\Desktop\neu1.txt")
Wkb.Worksheets("control").Unprotect Password:=""
Wkb.Worksheets("control").Cells(10, 1) = "bla"
Wkb.Worksheets("control").Cells(11, 1) = "bla"
Wkb.Worksheets("control").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, Password:=""
Wkb.Worksheets("data").Cells(18, 8) = "bla"
Wkb.Worksheets("data").Cells(20, 8) = "bla"
Wkb.Worksheets("data").Cells(35, 8) = "bla"
Wkb.Worksheets("data").Cells(37, 8) = "bla"
Application.DisplayAlerts = False
Wkb.Save
Wkb.Close SaveChanges:=False
strDatei = Dir()
Application.DisplayAlerts = True
Loop
Application.ScreenUpdating = True
Loop
AbortLoad:
Application.ScreenUpdating = True
Errorhandling:
If Err.Number = 9 Then MsgBox ("Wrong file!")
End Sub
Eventuell ist der Code an der ein oder anderen Stelle nicht ganz sauber. Aber funktionieren tut er ohne die Zeile "Wkb.VBProject.VBComponents("DieseArbeitsmappe").CodeModule.AddFromFile ("C:\Dokumente und Einstellungen\kai\Desktop\neu1.txt")" einwandfrei!!
Kann mir eventuell damit jemand weiterhelfen? Ich verzweifel bald