So I am trying to open Excel object and count columns but I keep getting Run time error 1004. Based on google, this code should be working?
Code:
Sub Validate_Columns(Filepath1 As String, StrName As String, TableName As String)
Dim xlApp As Object
Dim xlWS As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open (Filepath1 & StrName), True, False
Set xlWS = xlApp.ActiveWorkbook.Worksheets(1)
Dim lastColumn As Long
With xlWS
lastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
MsgBox lastColumn
Set xlApp = Nothing
End Sub