Search for Desktop folder name containing string

Laddy1992

New Member
Joined
Sep 14, 2013
Messages
2
Hi there. I'm extremely new to VBA and MS-Access.

I very simply need to have specific folder names on my desktop to appear in a msgbox when a form is loaded. This folder then needs to be copied to another location. The folder name contains the characters "BAC". Thus it could be aaBac2013 or bbBack2013. I'm stuck at after obtaining the desktop path. From there I need help. This is my code:

Private Sub Form_Load()
Dim spath As String
Dim strPartName As String
spath = Environ("USERPROFILE") & "\Desktop"
strPartName = "BAC"
MsgBox strPartName, , "strPartName"
End Sub

I know the code is incomplete... hence my request for assistance.
Thanking you
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hello

Welcome to MrExcel.

There you go:

Rich (BB code):
Sub wigi()

    Dim spath As String
    Dim strPartName As String


    spath = Environ("USERPROFILE") & "\Desktop"
    strPartName = "*BAC*"


    For Each f In CreateObject("scripting.filesystemobject").GetFolder(spath).subFolders
        If UCase(f.Name) Like strPartName Then Debug.Print f.Name
    Next


End Sub

Can you please use
Code:
 tags when you paste code on the forum?
Code tags format the code making it easier to read and hence follow the logic of the code.


You can use [CODE] tags in this way: 


Add the word [color=blue][b][PLAIN][code=rich][/PLAIN][/B][/color] before the first line of code, and
add the word [color=blue][b][PLAIN]
[/PLAIN][/B][/color] after the last line of code.


Or: you could use the "#" icon when changing / composing a message in the Advanced editing screen.


Thanks for your consideration.
 
Upvote 0
Wigi

You are the "BEST!!!!". it worked perfectly. Thank yoy very much. I take note of the tag request in future. I will be around more often. Wigi rocks!!!!
;)
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top