Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    May 2002
    Location
    Toronto, Ontario, Canada
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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!! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Opening workbooks in code with partial name... (2000 SP-3)

    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

  3. #3
    3 Star Lounger
    Join Date
    May 2002
    Location
    Toronto, Ontario, Canada
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening workbooks in code with partial name... (2000 SP-3)

    Works perfectly Hans... <img src=/S/doh.gif border=0 alt=doh width=15 height=15> 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!)... <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

    Thanks for helping me overcome another brain freeze! <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

Posting Permissions

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