+ Reply to Thread
Results 1 to 2 of 2

Error while opening the alternate workbooks i a folder.

  1. #1
    Registered User
    Join Date
    03-21-2013
    Location
    hyderabad
    MS-Off Ver
    Excel 2010
    Posts
    6

    Question Error while opening the alternate workbooks i a folder.

    Hi,

    This forum was always helpful to me in solving the queries which is the reason i come back and again whenever i face a problem with VBA.

    I was trying to open the alternate workbooks in the folder dallas and perform some copy and paste of the sheets.

    The hardest part was to open the alternate workbooks such as first,third and fifth so on.........leaving the second,fourth,sixth..........

    I wrote the below code which i thought should be working but when i really executed the macro,it is always opening the first workbook only..

    I dont understand what is the incorrect in the below code.Can someone help me out there............


    Sub files()

    Dim myfile As String
    Dim wb As Workbook
    Dim i As Integer
    i = 1
    myfile = Dir("C:\dallas\*xls")
    Do Until myfile = ""
    If (i Mod 2 = 1) Then
    Set wb = Workbooks.Open("C:\dallas\" & myfile)

    \\copy the required sheets\\

    wb.Close Savechanges
    Else
    MsgBox "number is not odd"
    End If
    sname = Dir()
    i = i + 1
    Loop

    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,088

    Re: Error while opening the alternate workbooks i a folder.

    Suspect this:

    Please Login or Register  to view this content.

    Should be:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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