Excel unresponsive/black after running macro from Access

krausr79

Board Regular
Joined
Feb 12, 2012
Messages
209
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:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Ran it with no error handling. There is no error handling in the excel macros. The result is the same.
 
Upvote 0
I tried working with this problem again. I'm able to do what I want by using a worksheet_change event in excel. I have the Access macro enter a code word in one of the cells, then when the worksheet_change sees the code word, it runs the macros from excel.
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,737
Members
449,185
Latest member
hopkinsr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top