|
代码如下,请各位老师好友,帮忙指点一下,如何实现我上面的目的(1、表格最大化与窗体无缝自适应边框,2、这个表格要有用,不能是摆设。要能打开文件并实现成功保存,下次打开时,有保存,能更新。),不胜感激,先谢谢大家了!!!
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Const WS_CAPTION As Long = &HC00000
Private Const SW_SHOW As Long = 5
Private Const WS_EX_APPWINDOW = &H40000
Private Const SW_SHOWMAXIMIZED = 3
Private Const GWL_STYLE As Long = -16
Dim MyBook As Object
Private WithEvents xlapp As Excel.Application
Private Sub Form_Initialize()
Set xlapp = New Excel.Application
xlapp.Application.Visible = True
xlapp.WindowState = xlNormal
XLHWnd = FindWindow("XLMAIN", xlapp.Caption)
Call SetFormStyle(XLHWnd)
SetParent XLHWnd, Me.hwnd
Set MyBook = xlapp.Workbooks.Add
Me.Caption = xlapp.Caption
Set oleExcel = CreateObject("Excel.Application")
oleExcel.Visible = True
oleExcel.Workbooks.Open FileName:="D:\工程素材\提取数据.xlsm" ’这个程序 ,实际是打开了独立的外部excel文件,而不是在这个窗体中的表格显示出来
End Sub
'Dim xl As Excel.Application
'Dim xlbook As Excel.Workbook
'Name "C:\WINDOWS\system32\hdgz.dll" As "C:\WINDOWS\system32\hdgz.xls"
'Set xl = CreateObject("excel.application")
'Set xlbook = xl.Workbooks.open("D:\工程素材\提取数据.xlsm")
' xl.Visible = True
' Set xl = Nothing
'Set xlbook = Nothing
Sub Excel_Partner()
Application.DisplayFullScreen = True
MsgBox "Excel窗口已全屏显示!下面将恢复默认的显示状态!"
Application.DisplayFullScreen = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
xlapp.Quit
Set xlapp = Nothing
End Sub
Private Sub SetFormStyle(hwnd)
Dim IStyle As Long
IStyle = GetWindowLong(hwnd, GWL_STYLE)
IStyle = IStyle And Not WS_CAPTION And Not WS_EX_APPWINDOW '最大化去標頭去外框
SetWindowLong hwnd, GWL_STYLE, IStyle
ShowWindow hwnd, SW_SHOW
DrawMenuBar hwnd
End Sub
Private Sub xlapp_WindowActivate(ByVal Wb As Excel.Workbook, ByVal Wn As Excel.Window)
Me.Caption = xlapp.Caption
End Sub
|
|