Defining a workbook that has a changing name VBA

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

This is turning out to be more of a challenge than I had anticipated. I am trying to define a name for a workbook that has a name that wont necessarily be the same for each time the macro is run. Below is the code as it sits currently...

Code:
Dim wb As WorkbookFor Each wb In Application.Workbooks
    If wb.Name <> "Products.xls" Or "General_Account_Ledger.xls" Or "PERSONAL.xls" Then
        wb.Sheets("Customer Funds Received").Range("B10").Copy
        wb.Sheets("Customer Ledger").Range("A3").Select

The purpose of the macro is to run through customer workbooks to copy and paste cells into the accounting workbooks while other workbooks are open (products.xls).

However, the structure and names of the worksheets within the workbooks(with different names) is the same. I am currently receiving an error on this line.

Code:
If wb.Name <> "products.xls" Or "General_Account_Ledger.xls" Or "PERSONAL.xls" Then

any suggestions on syntax would be appreciated
 
Last edited:

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.
Try:
Code:
If wb.Name <> "products.xls" Or wb.Name <> "General_Account_Ledger.xls" Or wb.Name <> "PERSONAL.xls" Then
Not sure what logic you want here, but you may want to replace Or with And as well if you only want to operate on an open workbook that isn't one of those you call out specifically.
 
Upvote 0
thanks for the quick reply!

I am trying to isolate a workbook name that changes. If I can isolate the workbook I would then like to define a name for the workbook to be used in the macro(as opposed to renaming the workbook) so that I can say stuff like copy from this workbook and paste to this workbook (a bunch of times).
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

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