You are on page 1of 2

Bc 1.

Design Ban qung Panel vao form

Bc 2. Thm dll Bc 3. Soan ma


Private Const WM_SYSCOMMAND As Integer = 274 Private Const SC_MAXIMIZE As Integer = 61488 Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As IntPtr, ByRef lpdwProcessId As IntPtr) As IntPtr

Dim _App As New Microsoft.Office.Interop.Excel.Application With {.Visible = True, .DisplayAlerts = False, .ShowWindowsInTaskbar = False} Dim _wb As Microsoft.Office.Interop.Excel.Workbook Dim _ws As Microsoft.Office.Interop.Excel.Worksheet Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized Dim processId As IntPtr GetWindowThreadProcessId(_App.Hwnd, processId)

Dim proce As Process = Process.GetProcessById(processId.ToInt32()) proce.WaitForInputIdle() SetParent(proce.MainWindowHandle, Me.PanelExcel.Handle) SendMessage(proce.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0) M file _wb = _App.Workbooks.Open(Application.StartupPath + "Tn file cua ban.xls") _Ws = CType(_wb.Sheets("Tn mt sheet nao o cua ban"), Microsoft.Office.Interop.Excel.Worksheet) con lai thao tac nh VBA

End Sub
Private Sub FrmNhap_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Dim msg As MsgBoxResult = MsgBox("C Save lai trc khi thot khng?", MsgBoxStyle.YesNoCancel, "Hi") Select Case msg Case MsgBoxResult.Cancel e.Cancel = True Exit Sub Case MsgBoxResult.Yes Save() End Select On Error Resume Next ban phai ong ng dung nu khng se thng bi li excel, kinh nghim cho thy nhiu tay ga bi cai nay _App.Workbooks.Close() _App.Quit() End Sub

You might also like