How to move Workbook that changes name?

ECUPIRATE

New Member
Joined
Jun 13, 2017
Messages
25
Hi. Here is the code I've created:

Windows("Banana Republic (99316).xls").Activate
Sheets("My Favorite Store").Move After:=Workbooks( _
"My Favorite Store Macro.xlsm").Sheets(1)
Sheets("Controls").Select



The goal is to be able to manually download the Banana Republic workbook and open it, then the Macro will find it on the desktop and move it to the Macro enabled workbook. The code above works successfully, however: The problem is that every time a new Banana Republic report is downloaded, the number (99136) changes. So the code will not work every time. What can I do to get this code to work?

Note = The Banana Republic workbook is downloaded from a reporting system from an online database, which is why the name changes upon each download. However, Sheets("My Favorite Store") does not change. There is only one sheet in the Banana Republic Workbook.

Also, if you know of a more efficient way to accomplish this, I am open eyes :eeek:; it runs a bit slow.

Thanks in advance! :)
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Untested, may need some tweaking:
Code:
Sub ECUPIRATE()
Dim Wb As Workbook
For Each Wb In Workbooks
    If Wb.Name Like "Banana Republic*.xls" Then
        Wb.Activate
        Exit For
    Else
        magbox "can't find Banana Republic workbook"
        Exit Sub
    End If
Next Wb
Wb.Sheets("My Favorite Store").Move After:=Workbooks( _
"My Favorite Store Macro.xlsm").Sheets(1)
Sheets("Controls").Select
End Sub
 
Upvote 0
Thanks JoeMo: The message box still comes up, despite it working - Otherwise this works perfectly!
 
Last edited:
Upvote 0
Thanks JoeMo: The message box still comes up, despite it working - Otherwise this works perfectly!

Sorry about that message box, I didn't code that correctly. This should fix it.
Code:
Sub ECUPIRATE()
Dim Wb As Workbook, Ct As Long
For Each Wb In Workbooks
    If Wb.Name Like "Banana Republic*.xls" Then
        Wb.Activate
        Exit For
    Else
        Ct = Ct + 1
        If Ct = Workbooks.Count Then
            MsgBox "can't find Banana Republic workbook among the open workbooks"
            Exit Sub
        End If
    End If
Next Wb
Wb.Sheets("My Favorite Store").Move After:=Workbooks( _
"My Favorite Store Macro.xlsm").Sheets(1)
Sheets("Controls").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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