Activate next workbook

Mladen82

New Member
Joined
Dec 20, 2018
Messages
8
Hi all,

Every day I export 4 workbooks from Navision. I would like to create a macro that will put all 4 workbooks into one and then do some calculations. The problem is that these workbooks have different names every day. Is there a way to activate the next workbook regardless of the name?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hello there. You can reference workbooks by number or in a for each loop - here are both ways:

VBA Code:
Sub ListBooks()
Dim wkbk As Workbook
For Each wkbk In Workbooks
   MsgBox wkbk.Name
Next
End Sub
Sub AnotherWay()
For i = 1 To Workbooks.Count
MsgBox Workbooks(i).Name
Next i
End Sub
 
Upvote 0
I think you dont understand me. I want to copy the data from all the workbooks to the first workbook so that I can work with the data later. However, in order to use "Workbooks (" ???. XLS "). Activate" I first need to rename them because each day is a different name. So I need to switch to another workbook to change my name. Later when I rename all 4 Workbooks to 1.xls 2.xls 3.xls and 4.xls then I can call them when I need them.
 
Upvote 0
Hi there. Yes, I understand your goal - the code I presented is one way of accessing all the workbooks without needing to know their names. This code should help you a bit more:
VBA Code:
Sub DoBooks()
Dim wkbk As Workbook
For Each wkbk In Workbooks
If wkbk.Name <> "MASTER" Then  'change MASTER to whatever you want your concatenated workbook to be called
   wkbk.Activate
 ' in here you can do the copy/paste etc. on each workbook in turn - don't use the name, just use wkbk
' if you are going to do any copy paste etc. make sure you switch between your MASTER wokbook and wkbk as necessary
End If

Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

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