17. september 2006 - 16:00Der er
8 kommentarer og 1 løsning
Indsæt bestemt værdi i samtlige regneark/arkfaner i biblioteket
I en biblioteksstruktur, som kan variere fra bruger til bruger, har jeg xx og yy antal regneakk liggende. xx regneark er mine grunddataark/dataudtræk hvormed jeg via makroer føder yy regnearkene. Succesfuld opdatering af yy regnearkene er afhængig af at en bestemt celle ( G6 ) i hver yy regneark, med tilhørende arkfaner er udfyldt med en bestemt værdi.
Kan jeg via en makro ( skjult for brugeren ) indsætte denne værdi i alle regneark/arkfaner. Jeg kender som udgangspunkt ikke yy regnearkenes navn/arkfanenavn/antal.
Jeg kender xx regnearkenes navn ... disse skal ikke opdateres, ligesom alle regneark ( xx og yy ) ligger / opdateres i samme bibliotek ( som navngives individuelt af brugerne ....
Støv, fibre og metalliske partikler kan påvirke både uptime, levetid og driftssikkerhed. Derfor arbejder flere datacentre systematisk med contamination control.
ThisWorkbook.Path benytter jeg til at bestemme/angive hvor filerne filerne ligger, de enkelte arkfaner havde jeg tænkt mig at få adgang til hed hjælp af
For each WS .... next ...
men hvordan indlæser jeg de ukendte regneark og gennemløber arkfanerne automatisk
Private Sub CommandButton1_Click() Dim OK As Boolean, I As Integer Sti = ThisWorkbook.Path
Set Fil = Application.FileSearch With Application.FileSearch .LookIn = Sti .FileType = msoFileTypeExcelWorkbooks For FundetFiler = 1 To .FoundFiles.Count NyWorkbook = .FoundFiles(FundetFiler) If Right(NyWorkbook, Len(ThisWorkbook.Name)) <> ThisWorkbook.Name Then ReDim MyWorkbook(1) P = 1 For Each ws In ThisWorkbook.Worksheets MyWorkbook(P - 1) = ws.Name ReDim Preserve MyWorkbook(P) P = P + 1 Next Workbooks.Open Filename:=NyWorkbook ActiveSheet.Select For Each ws In Worksheets OK = False For I = 1 To UBound(MyWorkbook) If ws.Name = MyWorkbook(I) Then OK = True End If Next If OK = False Then Sheets(ws.Name).Range("A1").Value = "Yes" End If Next ActiveWorkbook.Save ActiveWindow.Close End If Next End With End Sub
Private Sub CommandButton1_Click() Dim FS As FileSearch Dim FilePath As String, Fundet As String Dim I As Long, Y As Long Dim NyWorkbook Const Filespec = "*.xls"
FilePath = ThisWorkbook.Path Application.ScreenUpdating = False Set FS = Application.FileSearch With FS .LookIn = FilePath .Filename = Filespec .SearchSubFolders = False .Execute For Y = 1 To .FoundFiles.Count Fundet = .FoundFiles(Y) L = Len(ThisWorkbook.Name) If Fundet <> FilePath & "\" & ThisWorkbook.Name Then NyWorkbook = .FoundFiles(Y) ReDim MyWorkbook(1) P = 1 For Each ws In ThisWorkbook.Worksheets MyWorkbook(P - 1) = ws.Name ReDim Preserve MyWorkbook(P) P = P + 1 Next Workbooks.Open Filename:=NyWorkbook ActiveSheet.Select For Each ws In Worksheets OK = False For I = 1 To UBound(MyWorkbook) If ws.Name = MyWorkbook(I) Then OK = True End If Next If OK = False Then Sheets(ws.Name).Range("C6").Value = "Yes" End If Next ActiveWorkbook.Save ActiveWindow.Close End If Next End With Application.ScreenUpdating = False End Sub
Private Sub CommandButton1_Click() Dim FS As FileSearch Dim FilePath As String, Fundet As String Dim I As Long, Y As Long Dim NyWorkbook Const Filespec = "*.xls"
FilePath = ThisWorkbook.Path Application.ScreenUpdating = False Set FS = Application.FileSearch With FS .LookIn = FilePath .Filename = Filespec .SearchSubFolders = False .Execute For Y = 1 To .FoundFiles.Count Fundet = .FoundFiles(Y) L = Len(ThisWorkbook.Name) If Fundet <> FilePath & "\" & ThisWorkbook.Name Then Antal = Antal + 1 NyWorkbook = .FoundFiles(Y) ReDim MyWorkbook(1) P = 1 For Each ws In ThisWorkbook.Worksheets MyWorkbook(P - 1) = ws.Name ReDim Preserve MyWorkbook(P) P = P + 1 Next Workbooks.Open Filename:=NyWorkbook Application.StatusBar = "Retter " & Fundet ActiveSheet.Select For Each ws In Worksheets OK = False For I = 1 To UBound(MyWorkbook) If ws.Name = MyWorkbook(I) Then OK = True End If Next If OK = False Then Sheets(ws.Name).Range("C6").Value = "Yes" End If Next ActiveWorkbook.Save ActiveWindow.Close End If Next End With Application.StatusBar = "Rettede " & Antal & " filer" End Sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.