Type Mismatch when defining workbooks

PaulOPTC

New Member
Joined
Jan 13, 2022
Messages
48
Office Version
  1. 365
Platform
  1. Windows
Hello!

I am probably doing something wrong but I keep getting an error and I dont know how to fix it.

The long and the short of it is I have to copy data between three different excel workbooks

VBA Code:
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim wb3 As Workbook
'
Set wb1 = ActiveWorkbook
Set wb2 = wb1.Sheets("Link").Range("L8")
Set wb3 = wb1.Sheets("Link").Range("M8")


Thats pretty much where I fail, I get a mismatch error.


Eventually my code will go and use

wb2.activate

wb1.activate

wb3.activate


Swapping back and fourth between them.



WB2 and WB3 have very particualr names, and their names are defined based on the Cells L8 and M8 in worksheet "Link" on work book 1


their names are derived from:

=SUBSTITUTE(E8,"Proposals\","Estimates\Bid Template.xlsb") which turns into
C:\Users\USER\Desktop\NAME BID TEMPLATE.xlsb

It has no trouble using the L8 to rename the workbook2 (which it ends up doing in the code) so it should see it as a legit path


Any ideas? Stupid mistake?
 
use
VBA Code:
Set wb2 = Workbooks.Open (Range("L8"))

wb1.Activate
Sheets("Link").Select
Set wb3 = Workbooks.Open (Range("M8"))
wb1.Activate
Beautiful! It worked!

Thank you so much!
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You're welcome & thanks for the feedback.
 
Upvote 1

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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