Jeg har fået gumpet mig rundt i excel vba nu en del.. men kan ikke lige få bare folder navn
jeg ønsker at få omdøbt mit kopieret sheet til folder navn fra den orginale fil.
min kode ser således ud
Sub SrchForFiles() Dim i As Long, z As Long, Rw As Long Dim ws As Worksheet Dim y As Variant Dim fLdr As String, fil As String, FPath As String
y = "case.xls" Application.ScreenUpdating = False '********************************************************************** With Application.FileDialog(msoFileDialogFolderPicker) .Show fLdr = .SelectedItems(1) End With '********************************************************************** With Application.FileSearch .NewSearch .LookIn = fLdr .SearchSubFolders = True .Filename = y
On Error GoTo 0 If .Execute() > 0 Then For i = 1 To .FoundFiles.Count fil = .FoundFiles(i) 'Get file path from file name 'FPath = Left(fil, Len(fil) - Len(Split(fil, "\")(UBound(Split(fil, "\")))) - 1) Workbooks.Open Filename:=fil Sheets("Start").Select Sheets("Start").Copy After:=Workbooks("Opsamlingssheet.xls").Sheets(2) Windows("case.xls").Close (True)
AI bliver først for alvor en del af arbejdet, når teknologien integreres i den måde, vi arbejder på. At have adgang til AI betyder ikke nødvendigvis, at medarbejderne er klar til at bruge den.
Sub SrchForFiles() Dim i As Long, z As Long, Rw As Long Dim ws As Worksheet Dim y As Variant Dim fLdr As String, fil As String, FPath As String Dim MyTempList As Variant Dim lfldrnm As Integer Dim FldrName As String Dim FilName As String Dim sTmp As String Dim t As Long
y = "case.xls" Application.ScreenUpdating = False '********************************************************************** With Application.FileDialog(msoFileDialogFolderPicker) .Show fLdr = .SelectedItems(1) End With '********************************************************************** With Application.FileSearch .NewSearch .LookIn = fLdr .SearchSubFolders = True .Filename = y
On Error GoTo 0 If .Execute() > 0 Then For i = 1 To .FoundFiles.Count fil = .FoundFiles(i) 'Get file path from file name FPath = Left(fil, Len(fil) - Len(Split(fil, "\")(UBound(Split(fil, "\")))) - 1) Workbooks.Open Filename:=fil Sheets("Start").Select MyTempList = Split(fil, "\") For t = 0 To UBound(MyTempList) Next t FldrName = MyTempList(UBound(MyTempList) - 1) Sheets("Start").Copy After:=Workbooks("Opsamlingssheet.xls").Sheets(1) ActiveSheet.Name = FldrName Windows("case.xls").Close (True)
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.