1004 error when trying to run an excel Macro from Access

B

brupp24_6

Ok.. I've seen this problem all over the place but none of the answers seem
to apply to my problem.

In Acces (2k) i have a simple vba code that opens an excel workbook and runs
its macro. I have essentially the same code on 2 different controls (with
diff file and path names of course). The problem is that while control A
works fine... control B gets the 'run-time 1004 error - macro cannot be
found'. If I open the workbook manually and run the macro, it works fine. I
double, triple, quadruple, checked the paths, files, variables, etc... and
just can't figure this out.. I've included the code(s) below:

Thanks in advance for any light you might be able to shed.

'The one that sticks:
Private Sub cmd_VoidSetUp_Click()
On Error GoTo Err_cmd_VoidSetUp_Click

Dim xls As Object, xwkb As Object
Dim strFile As String, strMacro As String
strFile = "2004AccountVoids-DailyTemplateADM017.xls"
strMacro = "mrc_VoidSetup"
Set xls = CreateObject("Excel.Application")
xls.Visible = True

Set xwkb = xls.workbooks.Open("\\USMOPSF0ONS03\brupp10$\Desktop\2005 TEST
FOLDER.Data Integration & Access DB ADM017\void updates\" & strFile)
xls.Run strFile & "!" & strMacro



Exit_cmd_VoidSetUp_Click:
Exit Sub

Err_cmd_VoidSetUp_Click:
MsgBox Err.Description
Resume Exit_cmd_VoidSetUp_Click


'The one that works:
Private Sub cmd_capSetUp_Click()
On Error GoTo Err_cmd_capsetup_Click

Dim xls As Object, xwkb As Object
Dim strFile As String, strMacro As String
strFile = "CapTemplate_NewTblStructure.xls"
strMacro = "mcr_capsetup"
Set xls = CreateObject("Excel.Application")
xls.Visible = True
Set xwkb = xls.workbooks.Open("\\USMOPSF0ONS03\brupp10$\Desktop\2005 TEST
FOLDER.Data Integration & Access DB ADM017\cap udates\" & strFile)
xls.Run strFile & "!" & strMacro




Exit_cmd_capsetup_Click:
Exit Sub

Err_cmd_capsetup_Click:
MsgBox Err.Description
Resume Exit_cmd_capsetup_Click

End Sub


The Excel Macro that it can't find (excuse the excess junk, its recorded):
Sub mrc_VoidSetup()


ChDir _
"\\USMOPSF0ONS03\brupp10$\Desktop\2005 TEST FOLDER.Data Integration
& Access DB ADM017\void updates"
Workbooks.Open Filename:= _
"\\USMOPSF0ONS03\brupp10$\Desktop\2005 TEST FOLDER.Data Integration
& Access DB ADM017\void updates\Account Voids-Summary1.xls"
Cells.Select
With Selection
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("B3:H2000").Select
Range(Selection, Selection.End(xlUp)).Offset(1, 0).Select
Selection.AutoFilter _
field:=5, _
Criteria1:=">0"
Selection.Copy
Windows("2004AccountVoids-DailyTemplateADM017.xls").Activate
Range("b11").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("J11").Select
Windows("Account Voids-Summary1.xls").Activate
Range("I3:K2000").Select
Range(Selection, Selection.End(xlUp)).Offset(1, 0).Select
Application.CutCopyMode = False
Selection.Copy
Windows("2004AccountVoids-DailyTemplateADM017.xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.SmallScroll Down:=-21
Windows("AccountVoids-Summary1.xls").Activate



End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top