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
 

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
2,936
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.
 

Mp9

New Member
Joined
Aug 22, 2008
Messages
10
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 ---
 

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154
Is Remove() in a Standard Module (not a worksheet's module) in the other workbook? If yes, I'd first try renaming the Sub.
 

Mp9

New Member
Joined
Aug 22, 2008
Messages
10
It looks like this

-- removed inline image ---


-- removed inline image ---
 

Forum statistics

Threads
1,085,031
Messages
5,381,303
Members
401,733
Latest member
Kabasa007

Some videos you may like

This Week's Hot Topics

Top