Professional Documents
Culture Documents
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