josephgunter163
New Member
- Joined
- Nov 27, 2013
- Messages
- 6
Hey All,
I have code that loops through excel files in a file folder and edits those files. My trouble is that the code is also editing the workbook where the code is saved. Can you take a look at this code and tell me how I can exclude my workbook from the editing loop?
I have code that loops through excel files in a file folder and edits those files. My trouble is that the code is also editing the workbook where the code is saved. Can you take a look at this code and tell me how I can exclude my workbook from the editing loop?
Code:
Private Sub CommandButton2_Click() ' third step edit work sheets
Dim Myfile As String
Dim FilePath As String
Dim Q As Long
Dim NewYear As String
Dim ThisYear As String
Dim myobject As Worksheet
Dim path As String
Dim Folderyear As String ' added
Dim Folder As String ' added
Folderyear = Range("B11") ' added
Folder = Range("B12")
NewYear = Range("B9")
ThisYear = Range("B10")
FilePath = Folder + Folderyear
Myfile = Dir(FilePath)
Do While Len(Myfile) > 0
If Myfile = "*programcleanup*" Then
Exit Sub
End If
Workbooks.Open (FilePath & Myfile)
For Q = 1 To Application.Worksheets.Count
If Myfile = "*programcleanup*" Then
Exit Sub
End If
Worksheets(Q).Activate
'Range("C13:H25").Copy
'Range("B13").PasteSpecial
'Range("C39:E42").Copy
'Range("B39").PasteSpecial
Range("A20") = NewYear ' should be A3 changed to A20 for testing
'Range("H13") = NewYear
'Range("H39") = NewYear
'Range("E39") = ThisYear
'Range("G14") = "Budget"
Next Q
ActiveWorkbook.Save
ActiveWorkbook.Close
Myfile = Dir
Loop
End Sub
Last edited: