Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for / save in folder using wildcards 1

Status
Not open for further replies.

RP1America

Technical User
Aug 17, 2009
221
0
0
US
I need to revise the code below to allow for a wildcard.

frmPCSS.txtSRQ.Text will always be 8 digits. However, the folder I am searching for may include characters after those 8 digits.

Example:
Folder may be -
"SRQ12345678" or "SRQ12345678 - Test"

How can I update my code for the strPath and the .SaveAs to incorporate this possible wildcard?


Code:
Dim strPath As String
strPath = "K:\WMS\RS\Ideas\SRQ" & frmPCSS.txtSRQ.Text
If Dir(strPath, vbDirectory) = "" Then
    MkDir strPath
End If

ActiveWorkbook.SaveAs strPath & "\SRQ" & frmPCSS.txtSRQ.Text & " - Project Prep Checklist.xlsx", FileFormat:=51

Basically, there may or may not exist a folder. If it exists, I need the file to be saved in that folder. If it does not, I need to create the folder and save the file within. But again, if the folder already exists, it may have extra characters past what is being input by the user.

Thoughts?
 
One way:
Code:
Dim strPath As String, strDir As String, strTemp As String
strDir = "K:\WMS\RS\Ideas\"
strPath = "SRQ" & frmPCSS.txtSRQ.Text
strTemp = Dir(strDir & strPath & "*", vbDirectory)
If strTemp = "" Then
  MkDir strDir & strPath
Else
  strPath = strTemp
End If
ActiveWorkbook.SaveAs strDir & strPath & "\SRQ" & frmPCSS.txtSRQ.Text & " - Project Prep Checklist.xlsx", FileFormat:=51

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top