Why will this not work?

FluidPowerOne

New Member
Joined
Apr 9, 2013
Messages
2
I'm entirely stunned... I'm working on a method to develop cartesian products via VBA using modeling sequences for hydraulic compentry. Long story short, when I build macros, I test them with debug.print along the way to ensure Excel is accepting all my inputs.

Why.... is... this... not... working when I have had it work before? This macro sits in it's own module, and there is NO other coding anywhere else in the workbook. Why am I getting a Run-Time error 438 stating that this won't work, when I see absolutely nothing wrong with the way this is written. it's like, Excel suddenly doesn't recognize the word "range".

Sub Cartesian()

Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.Worksheets("Cartesian")
Dim aRng As Range
Set aRng = wb.ws.Range("A1")

Debug.Print aRnge.Address
Debug.Print wb.Name
Debug.Print ws.Name

End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I'm entirely stunned... I'm working on a method to develop cartesian products via VBA using modeling sequences for hydraulic compentry. Long story short, when I build macros, I test them with debug.print along the way to ensure Excel is accepting all my inputs.

Why.... is... this... not... working when I have had it work before? This macro sits in it's own module, and there is NO other coding anywhere else in the workbook. Why am I getting a Run-Time error 438 stating that this won't work, when I see absolutely nothing wrong with the way this is written. it's like, Excel suddenly doesn't recognize the word "range".

Sub Cartesian()

Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.Worksheets("Cartesian")
Dim aRng As Range
Set aRng = wb.ws.Range("A1")

Debug.Print aRnge.Address
Debug.Print wb.Name
Debug.Print ws.Name

End Sub
I was able to get around this by removing the wb. from the range assignment. Why has that worked before and not now?
 
Upvote 0
That could never have worked. A Workbook object does not have a ws property.
 
Upvote 0

Forum statistics

Threads
1,216,499
Messages
6,131,010
Members
449,613
Latest member
MedDash99

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