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

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,757
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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

rollis13

Active Member
Joined
Jul 30, 2012
Messages
438
Office Version
  1. 2016
Platform
  1. Windows
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' ?
 

Watch MrExcel Video

Forum statistics

Threads
1,132,785
Messages
5,655,282
Members
418,185
Latest member
snoogz2

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
Top