whirlwind147
08-11-2014, 03:07 AM
Hi,
I have very limited experience of VBA so I'm copying and pasting things together from all over the place to do the jobs I need excel to do. It's worked fine so far but I've got an issue with my current macro. I'm trying to rename a file but I keep getting errors. I just know that all of you who view this will spot the error immediately but I've tried a few things but none have worked. Here is what I have:
Private Sub CommandButton2_Click()
Sub RenameFile()
Dim src As String, dst As String, fl As String
Dim rfl As String
'Folder
src = Range("B111")
'File name
fl = Range("B108")
'Rename file
rfl = Range("B110")
On Error Resume Next
Name src & "\" & fl As src & "\" & rfl
If Err.Number <> 0 Then
MsgBox "Error: " & src & "\" & rfl
End If
On Error GoTo 0
End Sub
Any help will be greatly appreciated!
I have very limited experience of VBA so I'm copying and pasting things together from all over the place to do the jobs I need excel to do. It's worked fine so far but I've got an issue with my current macro. I'm trying to rename a file but I keep getting errors. I just know that all of you who view this will spot the error immediately but I've tried a few things but none have worked. Here is what I have:
Private Sub CommandButton2_Click()
Sub RenameFile()
Dim src As String, dst As String, fl As String
Dim rfl As String
'Folder
src = Range("B111")
'File name
fl = Range("B108")
'Rename file
rfl = Range("B110")
On Error Resume Next
Name src & "\" & fl As src & "\" & rfl
If Err.Number <> 0 Then
MsgBox "Error: " & src & "\" & rfl
End If
On Error GoTo 0
End Sub
Any help will be greatly appreciated!