+ Reply to Thread
Results 1 to 4 of 4

Opening all files in directory

Hybrid View

whisperinghill Opening all files in directory 01-13-2007, 09:46 AM
VBA Noob Hi, This any help ... 01-13-2007, 10:12 AM
whisperinghill Yes it does thanks VBA Noob ... 01-13-2007, 12:23 PM
VBA Noob Glad it helped VBA Noob 01-13-2007, 01:01 PM
  1. #1
    Registered User
    Join Date
    06-14-2004
    Posts
    52

    Opening all files in directory

    I have a macro, I would like to run on all files in a directory. But I only want it to open one file, run a macro and then close it and open the next file until it is through with the directory or through with selected files, either one would work.

    I am pretty sure something was posted like this, but I cannot seem to locate it.

    Anyone point me in the right direction?

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    This any help

    http://support.microsoft.com/kb/139724


    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    06-14-2004
    Posts
    52
    This any help
    Yes it does thanks VBA Noob

    Though I found one alittle easier to maniupulate from the same source.

    Here is Macro to remove headers in all wqord documents in the current directory. Just have to open one Word Doc in that directory and then trigger the Macro Cooooool

    Thanks
       Sub Header_remover()
    
           'Set "filenam" to the first matching file in the current folder.
           filenam = Dir("*.doc*")
    
           'Loop to open each matching file in the current folder.
           Do While Len(filenam) > 0
    
               On Error Resume Next
    
               'Opens the file.
               Documents.Open FileName:=filenam
    
               'Continues execution if there was no error opening the file.
               If Err = 0 Then
        ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
        Selection.MoveDown Unit:=wdLine, Count:=4, Extend:=wdExtend
        Selection.Cut
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
        Selection.MoveUp Unit:=wdLine, Count:=1
        Selection.TypeParagraph
        Selection.MoveUp Unit:=wdLine, Count:=1
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.Delete Unit:=wdCharacter, Count:=1
        Selection.PageSetup.TopMargin = InchesToPoints(0.44)
        
                   'Creates "newname" based on original Lotus file name.
                   newnam = Left(filenam, InStr(1, filenam, ".") - 1) & ".doc"
                   'Saves the new file as a Microsoft Excel normal file.
                   ActiveDocument.SaveAs FileName:=newnam, FileFormat:=xlNormal
                   'Closes the current file.
                   ActiveDocument.Close
               Else
    
                   'Display message if opening filenam was unsuccessful.
                   MsgBox "Unable to Open file: " & CurDir() & "\" & filenam
                   'Resets error checking.
                   Err = 0
    
               End If
    
               'Gets the next file name
               filenam = Dir()
               'Repeats the loop for all matching files in the current folder.
           Loop
    
       End Sub

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Glad it helped

    VBA Noob

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1