Running macro for another workbook - dosen't wrok

Mp9

New Member
Joined
Aug 22, 2008
Messages
10
Hi

I have a macro that is to run three macros in another file
Two of them run fine but the third I get an error on

This is the code for running the macros

Workbooks.Open Filename:=FileNameFolder & xlsmFile


Application.Run "'" & xlsmFile & "'!UpdateSummarySheet"
'woks fine
Application.Run "'" & xlsmFile & "'!CreateCostBreakdownSheet"
'works fine
Application.Run "'" & xlsmFile & "'!Remove"
'generates an error


This is the macro that I can't get to run from the other workbook
Is it the "Option Explicit" that is the problem?


Option Explicit
_______________________________________________________________________________________________
Public Sub Remove()
If MsgBox("Are you sure you want to delete the buttons?", vbOKCancel, "PCR Template") = vbCancel Then
Exit Sub
End If
Application.DisplayAlerts = False
Dim wb As Excel.Workbook
Set wb = ActiveWorkbook
Dim FileName As String
FileName = wb.Path & "" & Left(wb.Name, Len(wb.Name) - 5) & "_Cust.xlsm"
wb.SaveAs FileName

Dim ws As Excel.Worksheet
For Each ws In wb.Worksheets
wb.Sheets(ws.Name).Buttons.Delete
Next ws

Set ws = wb.Sheets("SupplierSheet")
ws.Visible = xlSheetHidden


Application.DisplayAlerts = True
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
OPTION EXPLICIT assists you in identifying if there is an error in your coding and where it is located.

Have you tried running that third macro, by itself, in the other file ? Does it really work or are you assuming such ?

If you step through that macro line by line, where does it error out ? (Place your cursor at the beginning of the macro, then press F8 one at a time.
If there is truly an error with the code it should provide an error code and highlight in yellow the line of code containing the error.
 
Upvote 0
Hi Logit and thanks for your interest :)

I have run them one by one but get the same result

this is the error I get from the "Remove" macro, It's like it can find it


-- removed inline image ---


When I open the Macro management dialog box it looks a little strange to me
Some of the macros have the file name infront of the macro name, that is not as it ussaly looks?
What I can see also the Module name is part of the "macro name" hmm...

-- removed inline image ---
 
Upvote 0
Is Remove() in a Standard Module (not a worksheet's module) in the other workbook? If yes, I'd first try renaming the Sub.
 
Upvote 0
It looks like this

-- removed inline image ---


-- removed inline image ---
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,417
Members
448,895
Latest member
omarahmed1

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