Constant Expression Required

wsnyder

Board Regular
Joined
Sep 23, 2018
Messages
224
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Using Excel 365.

My code is returning an error:
Compile error:
Constant expression required

I believe I declared the Constant correctly.
I tired to move the path directly to the function call, bypassing the constant declaration and it worked as expected.
Not sure what is goin on here?

Thanks,
-w

VBA Code:
Sub Test_GetFile()

    Const zPath As String = "\\Folder\Subfolder\SubSubFolder\SubSubSubFolder\SubSubSubSubFolder\"
    
    GetFileNames Path:=zPath
    'GetFileNames is a Function using FSO


End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I presume that you do not actually have this exact line in your code?

Const zPath As String = "\\Folder\Subfolder\SubSubFolder\SubSubSubFolder\SubSubSubSubFolder\"

If not, what is that actual line of code?
 
Upvote 0
I presume that you do not actually have this exact line in your code?

Const zPath As String = "\\Folder\Subfolder\SubSubFolder\SubSubSubFolder\SubSubSubSubFolder\"

If not, what is that actual line of code?
Thanks Peter,

It is a path to a file on company network
I copied and pasted the path to Windows Explorer.
I was able to navigate to the requested subfolder in W/E.

Thanks,
-w
 
Upvote 0
You would only get that error if there's something wrong with what you actually have in the code (eg you try and concatenate a cell value or variable into the path)
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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