run time erro

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Run time erro 1004

Run time erro 1004

resolvedResolved · High Priority · Version 2010

Freddie has attended:
Excel VBA Introduction course

Run time erro 1004

Hi Guys

I am having problems with the below code. I am getting a runtime erro 1004 and excel is telling me that the path is not recognised(?!) yet i've checked the path and it is correct - can you help?

Dim strFilePath As String
Dim MyFilea As String
Dim LatestFilea As String
Dim LatestDatea As Date
Dim LMDa As Date

strFilePath = "L:\ClientInterest\BAD-STATIC DATA\NA-rates\"

If Right(strFilePath, 1) <> "\" Then MyPatha = strFilePath & "\"

MyFilea = Dir(strFilePath & "*.xls", vbNormal)

Do While Len(MyFilea) > 0

LMDa = FileDateTime(strFilePath & MyFilea)

If LMDa > LatestDatea Then
LatestFilea = MyFile
LatestDatea = LMD
End If

MyFilea = Dir
Loop

Workbooks.Open strFilePath & LatestFilea

Best,

Freddie

RE: Run time erro 1004

Hi Freddie,

Thank you for the forum question.

I can spot an error in the below part of the code:


If LMDa > LatestDatea Then
LatestFilea = MyFile
LatestDatea = LMD
End If

Shouldn't it be:

If LMDa > LatestDatea Then
LatestFilea = MyFilea
LatestDatea = LMDa
End If

If you have OPTION EXPLICIT on top of your module Excel will point at this when you execute the code.

I hope that this will solve the issue.

If you Step your code with the locals window open you can follow the content of your variables and this can be very helpful with problems like this.





Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Thu 18 Feb 2016: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Concatenating Results of Formulas

To concatenate the results of formulas simply add the "&" after the formula or function closing bracket.

function1(....)&function2(.....)

see example Creating a range of monthly payments as text.

View all Excel hints and tips


Server loaded in 0.05 secs.