i need to run macro in some other workbook, how can i do that

prafvik

New Member
Joined
Jul 21, 2015
Messages
34
hi''

I hv two workbooks open,
one has macro code but anothr simple xlsx workbook

I want to run the macro in anther workbook which has no macro
how can I achieve this task

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Here is a simple example to show how you can do that. This is set to work if there are exactly two workbooks open, it will update the one that the macro that is running is NOT found in.
Code:
Sub Test()

    Dim wb As Workbook
    Dim srcWB As Workbook
    Dim dstWB As Workbook
    Dim wbCount As Long
    
'   Capture current workbook (with macros)
    Set srcWB = ActiveWorkbook
    
'   Loop through all other workbooks
    For Each wb In Application.Workbooks
'       Count open workbooks (excluding Personal workbook)
        MsgBox wb.Name
        If wb.Name <> "PERSONAL.XLSB" Then
            wbCount = wbCount + 1
            If wb.Name <> srcWB.Name Then
                Set dstWB = wb
            End If
        End If
    Next wb
    
'   Check to make sure only two workbooks open
    If wbCount <> 2 Then
        MsgBox "You do not have exactly two workbooks open"
    Else
'       Update cell A1 in first sheet of other workbook
        dstWB.Activate
        Sheets(1).Range("A1") = "This is a Test"
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,916
Members
448,533
Latest member
thietbibeboiwasaco

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