Hello, I am trying to update files of one of specific folder. I am using Do While loop to update these files. But I want to add condition. If in these excel files there is particular sheet with previous month name then loop should skip that file & move to next.
I am not even amateur in VBA programming. So I check microsoft help which suggesting that I can use 'Continue do ' but when I used it in my code it is giving Syntax error. My code is as follows
Sub file_folder_update()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook
folderPath = "C:\Users\Vidyanand\Documents\Error Test\" 'change to suit
If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
filename = Dir(folderPath & "*.xlsx")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)
sheetname = Format(Date - 30, "MMM YY")
Dim ws As Worksheet
Set ws = Sheets(sheetname)
If Not ws Is Nothing Then
continue do
Else
'Call a subroutine here to operate on the just-opened workbook
Call portfolio_worksheet_update
wb.Save
wb.Close
End If
filename = Dir
Loop
Application.ScreenUpdating = True
MsgBox "macro run finished"
End Sub
So could anyone please help me to correct this code?
Thanx in advance
Vidyanand
I am not even amateur in VBA programming. So I check microsoft help which suggesting that I can use 'Continue do ' but when I used it in my code it is giving Syntax error. My code is as follows
Sub file_folder_update()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook
folderPath = "C:\Users\Vidyanand\Documents\Error Test\" 'change to suit
If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
filename = Dir(folderPath & "*.xlsx")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)
sheetname = Format(Date - 30, "MMM YY")
Dim ws As Worksheet
Set ws = Sheets(sheetname)
If Not ws Is Nothing Then
continue do
Else
'Call a subroutine here to operate on the just-opened workbook
Call portfolio_worksheet_update
wb.Save
wb.Close
End If
filename = Dir
Loop
Application.ScreenUpdating = True
MsgBox "macro run finished"
End Sub
So could anyone please help me to correct this code?
Thanx in advance
Vidyanand