PDA

View Full Version : [SOLVED:] bizarre "object required"



ZweiBieren
10-16-2024, 05:46 PM
I get an "object required" error for an expression that works fine in the preceding statement. What I am trying to do is

Set mypath = Excel.ActiveWorkbook.Path
For testing I've broken it into steps. If I comment out the "set mypath" line, the two MsgBox lines display the expected values. Note that this includes printing wbxx.Path. But if I leave in the "set mypath" it fails on that line.

If mypath is declared, the result is a compile time error
31821

If I omit the declaration of mypath, there is a runtime error.
31822

WHAT is going on?
How do I get the path to the current workbook?
I am still on VBA 7.1.1143. But Workbook.Path really ought to work.

Thanks, Fred Hansen

Logit
10-16-2024, 06:39 PM
Excel sees wbxx.Path as a string ... which it is. A string of terms or characters representing where the workbook is located. Excel is expressing that it requires the path to be "Dim" as a string for it to function correctly.

It really isn't any thing more than that. :friends:

arnelgp
10-16-2024, 08:35 PM
you use Set to assign Object to a variable.
If your variable is Not an Object type, you use Let (with or without it)

myPath = wbxx.Path

Or

Let myPath = wbxx.Path

ZweiBieren
10-18-2024, 06:23 AM
Thanks. I was finally able to get my function to work.