Avatar billede igoogle Forsker
13. marts 2009 - 12:01 Der er 1 løsning

Åbne og lukke workbook

Hej,

Hvordan får man åbnet og lukket en workbook

mit forsøg ser således her ud, det med fed er min tilføjelse på et fundet script .. http://www.vbaexpress.com/kb/getarticle.php?kb_id=800

Option Explicit

Sub SrchForFiles()
    ' Searches the selected folders and sub folders for files with the specified
    'extension.  .xls, .doc, .ppt, etc.
    'A new worksheet is produced called "File Search Results".  You can click on the link and go directly
    'to the file you need.
    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 = Application.InputBox("Please Enter File Extension", "Info Request")
    If y = False And Not TypeName(y) = "String" Then Exit Sub
    Application.ScreenUpdating = False
    '**********************************************************************
    'fLdr = BrowseForFolderShell
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Show
        fLdr = .SelectedItems(1)
    End With
    '**********************************************************************
    With Application.FileSearch
        .NewSearch
        .LookIn = fLdr
        .SearchSubFolders = True
        .Filename = y
        Set ws = ThisWorkbook.Worksheets.Add(Sheets(1))
        On Error GoTo 1
2:                      ws.Name = "FileSearch Results"
        On Error GoTo 0
        If .Execute() > 0 Then
            For i = 1 To .FoundFiles.Count
                Fil = .FoundFiles(i)
                    'Get file path from file name
                Workbooks.Open Filename:=Fil
                Sheets("Start").Select
                Sheets("Start").Copy After:=Workbooks("Opsamlingssheet.xls").Sheets(2)
                ActiveWorkbooks.Close (True)


               
                'FPath = Left(Fil, Len(Fil) - Len(Split(Fil, "\")(UBound(Split(Fil, "\")))) - 1)
                'If Left$(Fil, 1) = Left$(fLdr, 1) Then
                '  If CBool(Len(Dir(Fil))) Then
                  '      z = z + 1
                  '    ws.Cells(z + 1, 1).Resize(, 4) = _
                  '    Array(Dir(Fil), _
                  '    FileLen(Fil) / 1000, _
                  '    FileDateTime(Fil), _
                  '    FPath)
                  '    ws.Hyperlinks.Add Anchor:=Cells(z + 1, 1), _
                  '    Address:=.FoundFiles(i)
                  ' End If
                'End If
            Next i
        End If
    End With
   
     
    Exit Sub
1:          Application.DisplayAlerts = False
    Worksheets("FileSearch Results").Delete
    Application.DisplayAlerts = True
    GoTo 2
End Sub
Avatar billede igoogle Forsker
16. marts 2009 - 13:49 #1
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)
                                     
                'FPath = Left(fil, Len(fil) - Len(Split(fil, "\")(UBound(Split(fil, "\")))) - 1)
               
            Next i
        End If
    End With
   
     
    Exit Sub

End Sub
Avatar billede Ny bruger Nybegynder

Din løsning...

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.

Loading billede Opret Preview
Kategori
Excel kurser for alle niveauer og behov – find det kursus, der passer til dig

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester