I get a runtime error if I close excel and try to run the same sub again. It opens a blank Excel spreadsheet, the errors on the red bold code.
Runtime Error 1004 Method of 'Sheets' of object'_Global' failed
Code:
Set xlApp = New Excel.Application xlApp.Visible = True
Set WkBkA = xlApp.Workbooks.Add ' Add a new workbook
Set WKSht = WkBkA.Sheets(1)
Sheets(1).Name = "ROM_" & TODA ' Name Sheet Tab
I have tried adding Before the above code. Its already at the end of the code.
Code:
Set RU = Nothing Set WKSht = Nothing
Set WkBkA = Nothing
Set xlApp = Nothing
If I run
Code:
Dim sKillExcel As String sKillExcel = "TASKKILL /F /IM Excel.exe"
Shell sKillExcel, vbHide
killing all Excel in memory.
I get Runtime error 462 The remote machine or server does not exist or is unavailable at the same red bold code.
One would think that Set xlApp = New Excel.Application would open a new Excel allowing the code to run. Albeit it's not a good thing to do if you want other excel sheets open at the same time.
Code:
Set xlApp = New Excel.Application xlApp.Visible = True
Set WkBkA = xlApp.Workbooks.Add(strFilePath & "ROM_" & TODA) ' Add a new workbook
Set WKSht = WkBkA.Sheets(1)
WkBkA.Sheets(1).Name = "ROM_" & TODA ' Name Sheet Tab
WkBkA.Sheets("ROM_" & TODA).Activate
WkBkA.Sheets(1).Columns("A:B").ColumnWidth = 20
Works until I hit
Code:
Range("B2:E2").Select
Selection Merge
and requires
Code:
WkBkA.Sheets(1).Range("B2:E2").Merge
Then cannot find object variable with
Code:
With Selection.Font
.Name = "Calibri"
.Size = 11
.FontStyle = "Bold"
End With
The more I dig into this the worse its getting. It was fine with the exception of erroring out every other run of the sub with the runtime error 1004.