You are here Embed Zalo application in Excel with Task Pane in BSAC

Embed Zalo application in Excel with Task Pane in BSAC

VBA programming embeds Zalo application in Excel so that you can work and chat with Zalo conveniently, or "someone" can't see you are opening Zalo, just Excel. In this example, I just want to talk about the technique of using BSTaskPane to create a Task Pane window in Excel, for example embedding an external application in this window. Please follow this video step by step. The source code is sent in this article, or you can download the BSAC installer.
Detailed step-by-step video instructions:
The content in the video tutorial includes:
Embed the BSAC.ocx library in the VBAProject.
+ In the VBA window, select the VBAProject - the file you want to embed BSAC
+ Go to Tools menu -> References... When the window appears, select "Browser...", select the file type "ActiveX Controls". Go to the folder containing BSAC.ocx. With 32-bit Excel, the folder C:\Windows\SysWow64; For 64-bit Excel, the folder C:\Windows\System32, select the file "BSAC.ocx"



Source code:
Go to menu "Insert" - > Module and paste the code below into the right window.

Option Explicit 
'Author: Nguyen Duy Tuan -
#If VBA7 Then 
Public Declare PtrSafe Function CountFileInProcess Lib "BSAC.ocx" (ByVal FileName As Variant) As Long 
Public Declare Function CountFileInProcess Lib "BSAC.ocx" (ByVal FileName As Variant) As Long 
#End If 
Dim TP As BSTaskPane 

Sub CreateTpZalo() 
   Dim TPs As New BSTaskPanes  'Task Pane list
   Dim MustCreate As Boolean 
   Dim Title As String: Title = "Task Pane: Zalo"  'It is the same in sub DestroyTpZalo()
   ' + Userform
   ' + Handle to window
   ' + ClassName:Title (if only find class name then "ClassName:"
   ' + Title
   'In this demo, "Zalo" is title of Zalo App
   'Class and Title of appilcation use "Spy++ tool" or other to find
   If CountFileInProcess("Zalo.exe") = 0 Then 
      MsgBoxW "Please run Zalo app.", vbCritical, "Zalo not running" 
      Exit Sub 
   End If 
   If Not TP Is Nothing Then 
      MustCreate = TP.Client.SinkControl = 0  'Not success
      If Not MustCreate Then  'Exists, check is it Zalo?
         If TP.Caption  Title Then 
            If MsgBoxW("Do you want to remove TP and recreate it?", VbMsgBoxStyle.vbQuestion + vbYesNo, "Create Zalo") = vbYes Then 
               Set TP = Nothing 
               MustCreate = True 
            End If 
         End If 
      End If 
      MustCreate = True 
   End If 
   If MustCreate Then 
      Set TP = TPs.Add(Title, "Zalo", False, dpLeft) 
      TP.AllowHide = False  'Prevent user from clicking on "X" of Task Pane
      TP.Visible = True 
   End If 
   Set TPs = Nothing 
End Sub  
Sub DestroyTpZalo() 
   Dim TPs As New BSTaskPanes 
   'TPs.Clear 'Clear all task panes
   Dim Title As String: Title = "Task Pane: Zalo" 
   Dim Idx As Long 
   If TPs.Count > 0 And TP Is Nothing Then  'try to get instance of Task pane if it is lost
      'Variable "TP" may be lost when you have a bug anywhere
      Idx = TPs.IndexOf(Title)  'Find TP with Title in TaskPane list (BSTaskPanes)
      If Idx >= 0 Then 
         Set TP = TPs(Title) 
      End If 
   End If 
   If Not TP Is Nothing Then  'Only Zalo app
      Set TP = Nothing 
   End If 
   Set TPs = Nothing 
End Sub 

Explain more


In the above code, the command creates a new Task Pane and embeds the application, the command Set TP = TPs.Add(...) you pay attention to the parameter "SinkControl". This parameter can be the following values:
+ Userform
+ "Title of Window" - Title/Caption, in the above example the window title is "Zalo"
+ Is the class name and title of the window, structure "Class:Caption". "Class" is the class name of the Window, "Caption" is the title of the application window.
How to run macros in VBA
Before running the code on Zalo you must be open!
According to the above example we have 2 macros: CreateTpZalo(), DestroyTpZalo()
Method 1: place the cursor in the code block of a macro you want to run (for example inside CreateTpZalo), press F5.
Method 2: In the spreadsheet user environment, press F8, select the macro and then "Run"
Method 3: assign a macro to the command button: Go to the "Developer" tab -> Insert -> CommandButton and then assign the macro.
BSAC is an activex control with only one file that needs to be installed on the computer "BSAC.ocx". If you install Add-in A-Tools, BSAC is automatically installed. If you only want BSAC in your computer, read the detailed instructions on how to install it in the BSAC installer.
Download BSAC
Author: Nguyen Duy Tuan