Sunday, 27 September 2015

How to Call and Run a Macro from Another Workbook

How to Run a Macro from Another Workbook
When we want to run a Macro from an event or from another Macro in the same Workbook , We can call the Macro like this in code :

Call MyMacroName

But if we want to run a macro that is in another workbook or Add-In(File or add-in must be open).
We can use Application.Run as follows :

Application.Run "MyWorkBook.xls!MyMacroName"

Case I : Suppose if the Workbook name is not known in advance and its dynamically declared in a variable then we call the Macro as follows :


Application.Run " '" & strFileName & "'!MyMacroName"

Case II :Suppose if the Macro is specific to particular Worksheet Event , then we need to specify the Sheet name along with Macro name as follows :

Application.Run " '" & strFileName & "'!Sheet1.MyMacroName"

Please Note :
To get the Exact Macro name , we need to go to Macros in Excel Workbook where we can see all the Macros with Correct names to be use as reference for Calling/Running.

Thanks,
TAMATAM

Saturday, 5 September 2015

How to Update a Target Table by Mapping with another Table in SQL Server

SQL Query to Update a Target Table by Mapping with another Table in SQL Server
Suppose , we have a Target Table called 'Tbl_Customers', in which the columns [Cust_Segment] and [Bookings_Flag] are need to update by Mapping it with a another Table called 'Map_Table' . we can do it by using the Update query with Where clause as follows..


UPDATE [Tbl_Customers]
SET [Cust_Segment] = M.[CustSegment],
[Bookings_Flag]= CASE WHEN M.[Bookings_Type]='Product' THEN 'Prod' ELSE 'Svc' END
From [Tbl_Customers] C, [Map_Table] M
Where C.Cust_Id=M.CustId



Thanks,
TAMATAM

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts