Edit this macro so it can check if there is the personal workbook being used

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have this code below which works great,
it copies data from one open workbook to another,
it checks if there are only the two workbooks open before runing, however i get a problem when someone has a personal workbok as well as stricktly speaking this is open
is i was woundering if we could somehow edit this code to say if personal workbook is open count should be 3 and copy all but personal?

heres the code

VBA Code:
Sub CopyData()
    If Application.Workbooks.Count > 2 Then 'so this needs to be 3 if personal is in use!
        MsgBox ("Too many documents open.")
        Exit Sub
    End If
    Application.ScreenUpdating = False
    Dim WB As Workbook
    For Each WB In Workbooks ' except personal?
        If WB.Name <> ThisWorkbook.Name Then
            WB.ActiveSheet.UsedRange.Copy Sheets("raw data").Cells(1, 1)
        End If
    Next WB
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Since you are using in your macro Application.Workbooks.Count > 2 to exit, if there are more than 2 open workbooks, and WB.ActiveSheet.UsedRange.Copy then I suppose that you probably know the name of the other open workbook, so, why not use the 'name' of the workbook instead of 'WB' ?
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,166
Members
448,870
Latest member
max_pedreira

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