我使用以下脚本打开Excel文件。该脚本运行正常,从未遇到任何问题,除了现在。
所以这就是我所拥有的:我使用VBScript打开Excel。在Excel应用程序中,我单击打开另一个Excel文件,写入一些数据,然后关闭它并继续在我打开的第一个工作簿中工作。问题是当我运行宏时,Excel只是崩溃并关闭它。我知道如果我自己打开Excel,我没有问题。
Dim xlApp
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open "H:\APPLICATIONS\SEAT AUDIT\APP\SEAT AUDIT.xlsm"
Set xlApp = Nothing
这是导致Excel崩溃的宏:
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