Setting Workbook variables

iamjmks

New Member
Joined
Dec 5, 2017
Messages
5
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!

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)
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top