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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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