+ Reply to Thread
Results 1 to 3 of 3

VB Code

Hybrid View

  1. #1
    Registered User
    Join Date
    09-20-2006
    Posts
    47

    VB Code

    Hi all,

    I have a piece of code which works fine but i want to shorten it a bit. The original code runs and looks in 3 areas of one file and so i have to write the code 3 times. However i now want it to look in location 1, then 2 then 3.

    The basic code i have is

    Sub Auto_Update()
    
    With Application.FileSearch
    .NewSearch
    .LookIn = "m:\Excel1"
    .SearchSubFolders = False
    .Filename = "*.xls"
    
    .FileType = msoFileTypeExcelWorkbooks
    If .Execute() > 0 Then
    For i = 1 To .FoundFiles.Count
    Application.ScreenUpdating = False
    Workbooks.Open Filename:=.FoundFiles(i), UpdateLinks:=3
    Application.StatusBar = "Updating Links " & .FoundFiles(i)
    ActiveWorkbook.Save
    ActiveWindow.Close
    
    Next i
    End If
    End With
    The bit in red is what i wnat it to look at but then also in 2 other locations. Say
    m:\Excel2
    m:\Excel3

    Any Help is appreciated.

    Cheers

  2. #2
    Registered User
    Join Date
    09-20-2006
    Posts
    47
    Knock Knock

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Try this



    Sub MainMacro()
    Call Auto_Update("m:\Excel1")
    Call Auto_Update("m:\Excel2")
    Call Auto_Update("m:\Excel3")
    End Sub


    Sub Auto_Update(sFile As String)

    With Application.FileSearch
    .NewSearch
    .LookIn = sFile
    .SearchSubFolders = False
    .Filename = "*.xls"

    .FileType = msoFileTypeExcelWorkbooks
    If .Execute() > 0 Then
    For i = 1 To .FoundFiles.Count
    Application.ScreenUpdating = False
    Workbooks.Open Filename:=.FoundFiles(i), UpdateLinks:=3
    Application.StatusBar = "Updating Links " & .FoundFiles(i)
    ActiveWorkbook.Save
    ActiveWindow.Close

    Next i
    End If

    End Sub

+ 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