I have a VBA macro I run from MS Access. It finds a particular open worksheet, adds data to it, and runs some macros in it. Everything seems to run properly, but after I click OK on the messagebox at the end of the excel macro the excel screen goes black and unresponsive. If I run the macros myself from Excel everything is fine. Ideas? Here's the Access macro:
Code:
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim WS As Worksheet
Dim DB As Database
Dim qdf As QueryDef
Dim rs As DAO.Recordset
Dim EIAC As String
If Nz(Me.txtPCCN, "") = "" Then
MsgBox ("Select a system")
Exit Sub
End If
EIAC = DLookup("EIACODXA", "qryPCCNtoEIAC", "PCCNUMXC='" & Me.txtPCCN & "'")
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application") 'Find excel
If Err.Number <> 0 Then MsgBox ("Couldn't find excel"): Exit Sub
On Error GoTo 0
For Each xlWB In xlApp.Workbooks 'check each workbook
For i = 1 To xlWB.sheets.Count 'check each worksheet
If InStr(1, UCase(CStr(xlWB.sheets(i).Name)), "Instructions") > 0 Then
If WS Is Nothing Then
Set WS = xlWB.sheets(i)
Else
MsgBox ("More than one sheet with Instructions in the name found. Exiting.")
Exit Sub
End If
End If
Next i
Next xlWB
If WS Is Nothing Then MsgBox ("Couldn't find Instructions sheet"): Exit Sub
Set DB = CurrentDb
WS.Range("A12:D20000").ClearContents 'clear recieving area in Excel
'Add path to file
WS.Range("I9").Value = Me.txtChgFile
'get all checked out LCNs
Set qdf = DB.QueryDefs("qryLCNsCO")
qdf.Parameters(0).Value = Me.txtPCCN
Set rs = qdf.OpenRecordset
WS.Range("C12").CopyFromRecordset rs
'get all CagePNs for checkouts
Set qdf = DB.QueryDefs("qryRetrieveCO")
qdf.Parameters(0).Value = Me.txtPCCN
Set rs = qdf.OpenRecordset
WS.Range("D12").CopyFromRecordset rs
'run macros
xlApp.Run "GetData"
xlApp.Run "FilterChg"
Last edited by a moderator: