• Opening workbooks in code with partial name… (2000 SP-3)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Opening workbooks in code with partial name… (2000 SP-3)

    Author
    Topic
    #408310

    Here’s what I have… Column A contains 6 character strings… These strings represent the first 6 characters of .xls file names (all unique to one particular file) in a certain directory… I need to loop through the list… opening the file, doing some other stuff and then closing the file…

    I can’t get the file to open… I’ve done this code many times with the FULL file names… I thought that I could use a wildcard character when specifying which file to open, but it’s not working… Is this possible??

    Thanks All!! smile

    Viewing 1 reply thread
    Author
    Replies
    • #860909

      Something like this:

      Dim strPath As String
      Dim strFile As String
      Dim wbk As Workbook

      strPath = “C:Excel” ‘ note the trailing backslash
      strFile = Dir(strPath & Range(“A1”) & “*.xls”)
      Do While Not (strFile = “”)
      Set wbk = Workbooks.Open(strPath & strFile)

      wbk.Close SaveChanges:=True ‘ or False
      strFile = Dir
      Loop

      • #860914

        Works perfectly Hans… doh My code was almost identical…
        I won’t tell you what I was missing or you’ll lose all respect for me (If you ever had any!)… laugh

        Thanks for helping me overcome another brain freeze! thankyou

      • #860915

        Works perfectly Hans… doh My code was almost identical…
        I won’t tell you what I was missing or you’ll lose all respect for me (If you ever had any!)… laugh

        Thanks for helping me overcome another brain freeze! thankyou

    • #860911

      Something like this:

      Dim strPath As String
      Dim strFile As String
      Dim wbk As Workbook

      strPath = “C:Excel” ‘ note the trailing backslash
      strFile = Dir(strPath & Range(“A1”) & “*.xls”)
      Do While Not (strFile = “”)
      Set wbk = Workbooks.Open(strPath & strFile)

      wbk.Close SaveChanges:=True ‘ or False
      strFile = Dir
      Loop

    Viewing 1 reply thread
    Reply To: Opening workbooks in code with partial name… (2000 SP-3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: