Workbook setting incorrectly VBA

LRoy

New Member
Joined
Aug 5, 2022
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to set two different workbooks so that VBA can distinguish between the two.

I have named one CurrentWB which is the workbook I'm currently using and creating the Sub for, and the other ComponentWB which is the workbook I intend to extract data from.

I have set CurrentWB as ThisWorkbook and have set ComponentWB as "Component Data.xlsx", which is the name of the component workbook.

However, when I step through the code it keeps setting ComponentWB as ThisWorkbook also. Does anyone have any ideas why?

The ComponentWB is not the workbook I am writing the code in so I'm unsure why it is setting as ThisWorkbook, especially when I have told it to set to "Component Data.xlsx"

Any help would be appreciated,
Thank you

1691149235879.png
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I suspect that it is setting the ComponentWB correctly, you are just not using it, neither are you using CurrentWS
 
Upvote 0
I suspect that it is setting the ComponentWB correctly, you are just not using it, neither are you using CurrentWS
Hi Fluff, thank you for your reply. Do you mind elaborating please? If I'm telling VB to set the ComponentWB to a specific file name, why is it setting it to ThisWorkbook? I have the file open and I want to refer to it in the code, but currently I'm unable to as I can't set it properly.
 
Upvote 0
If you expand the ComponentWB & look for the workbook name you will probably find that it is setting it to the correct workbook.
 
Upvote 0
Solution
If you expand the ComponentWB & look for the workbook name you will probably find that it is setting it to the correct workbook.
You're right it is. Because CurrentWB and ComponentWB were showing as the same thing under 'Type' I thought VB was viewing them as the same workbook. Thanks for clearing that up for me!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,140
Messages
6,123,269
Members
449,093
Latest member
Vincent Khandagale

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