Simple Compile Error - Expected End Sub

rahulsteel

New Member
Joined
Apr 3, 2019
Messages
11
I'm really new to VBA coding and would highly appreciate if you can help me with the error as per the screenshot

hmRVfHr

<a href="https://ibb.co/hmRVfHr"><img src="https://i.ibb.co/ZM6xmKv/Compile-error.png" alt="Compile-error" border="0"></a>

https://ibb.co/hmRVfHr
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi & welcome to MrExcel.
Just add the words in red as shown
Code:
Exit Sub
[COLOR=#ff0000]End Sub[/COLOR]
 
Upvote 0
Ok, Brand new to VBA. As of this morning brand new. I'm attempting to create a workbook that will list all files in a folder. Got it! What I don't have is the macro to update each time I open. Constantly get the compile error. Any advice? Below is the code I'm using. Thanks in advance!!

Sub Workbook_Open()

Sub LoopThroughFiles()

Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim i As Integer

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFolder = oFSO.GetFolder("C:\Users\admin\Dropbox\Steph-Frank\_posted")

For Each oFile In oFolder.FILES

Cells(i + 1, 1) = oFile.Name

i = i + 1

Next oFile


End Sub
 
Upvote 0
Hi fr_Mu,

Welcome to the MrExcel forum.

You really should have started a new thread with your question as opposed to adding it to an existing thread. That said, if you want your code to execute every time you open the workbook, make sure that the code is put into the "ThisWorkbook" module and remove this line:

VBA Code:
Sub LoopThroughFiles()

which is the line that is preventing the code from compiling.
 
Upvote 0
My apologies. I posted to this one because of the Thread title. Works perfect! Thank you!!
 
Upvote 0
You're welcome. I was happy to help.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

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