I am having issues with setting workbook variables. After numerous searches and reading posts, I don't ever find a satisfactory answer as to why my code doesn't seem to work. I have had this issue with a few different projects. Here is my most recent issue.
I am attempting to remove some extraneous data from csv files. The code is in one workbook and opens a series of files listed on a worksheet, one by one, looks for certain fields and blank rows to delete, then saves and closes the file and opens the next. wash, rinse, repeat.
The issue seems to be related to the ThisWorkbook object. There is more to the code than I have shown here - I know that this will not work as is. The last line of the code shown below is where it breaks. I get a 438 error - 'Object doesn't support property or method'.
Thanks in advance!
I am attempting to remove some extraneous data from csv files. The code is in one workbook and opens a series of files listed on a worksheet, one by one, looks for certain fields and blank rows to delete, then saves and closes the file and opens the next. wash, rinse, repeat.
The issue seems to be related to the ThisWorkbook object. There is more to the code than I have shown here - I know that this will not work as is. The last line of the code shown below is where it breaks. I get a 438 error - 'Object doesn't support property or method'.
Thanks in advance!
Code:
Sub Scrub_File()
Dim fileAddr As String
Dim dstFldr As String
Dim fileNmOnly As String
Dim FinalRow As Integer
Dim FinalCol As Integer
Dim flCnt As Integer
Dim r As Integer
Dim c As Integer
Dim i As Integer
Dim wkb1 As Workbook
Set wkb1 = ThisWorkbook
Dim wkb2 As Workbook
'Count the number of files found
r = Range("tblHdr").Row
c = Range("tblHdr").Column
FinalRow = Cells(Rows.Count, c).End(xlUp).Row
flCnt = FinalRow - r
'Destination Directory; Add \ if needed
dstFldr = Range("scrbFldr")
If Right(dstFldr, 1) <> "\" Then
dstFldr = dstFldr & "\"
End If
For i = 1 To flCnt
fileNmOnly = wkb1.Range("tblHdr").Offset(i, 1)