I am using the below script to open an Excel file. The script works fine and have never ran into any issues, except now.
So this is what I have: I open Excel using VBScript. Within the Excel app I click to open another Excel file, write some data, then close it and continue working away in the first workbook I opened. The problem is when I run the macro, Excel just crashes and closes it. I know that if I open Excel on its own, I have no issues.
Dim xlApp
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open "H:\APPLICATIONS\SEAT AUDIT\APP\SEAT AUDIT.xlsm"
Set xlApp = Nothing
and this is the macro that causes Excel to crash:
Sub log()
Dim rng As Range
Dim nwb As Workbook
Dim FileName As String
Dim var
Dim var1
Dim var2
Dim var3
Dim var4
Dim var5
var1 = frmsetup.cmbauditor.Text
var2 = frmsetup.lblsequence.Caption
var3 = frmsetup.cmbtrimstyle.Text
var4 = Format(Now, "yyyy-mm-dd")
var5 = "SEQ-" & frmsetup.lblsequence.Caption & " "
FileName = var5 & var4
Set nwb = Workbooks.Open("H:\APPLICATIONS\SEAT AUDIT\LOG FILES\Seat Audit Log.xlsx")
Dim emptyRow As Long
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
Set rng = Cells(emptyRow, 5)
rng.Parent.Hyperlinks.Add Anchor:=rng, Address:="H:\APPLICATIONS\SEAT AUDIT\QUERY RESULTS\SEAT AUDIT - PDF\" & FileName & ".pdf", TextToDisplay:="CLICK HERE!"
Cells(emptyRow, 1).Value = var1
Cells(emptyRow, 2).Value = var2
Cells(emptyRow, 3).Value = var3
Cells(emptyRow, 4).Value = var4
ActiveWorkbook.Save
ActiveWindow.Close
End Sub