作者:秋夜里的寂寞 | 来源:互联网 | 2023-10-12 10:21
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) 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 DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION As Long = &HC00000
Private Sub Form_Load()
Dim hwnd&
' Dim xlApp As New excel.application'如果在工程中引用了EXCEL下句声明不要
Dim xlApp As Object
If IsFileOpen(App.Path & "\" & Dir("*.dll")) Then _
MsgBox App.EXEName & " 文件已经打开!", vbInformation, "系统提醒:": GoTo ooo
DoEvents
Set xlApp = CreateObject("Excel.Application") '如果在工程中引用了EXCEL这句可不要
xlApp.Workbooks.Open (App.Path & "\" & Dir("*.dll"))
hwnd = FindWindow(vbNullString, xlApp.Caption)
SetWindowLong hwnd, GWL_STYLE, IStyle
DrawMenuBar hwnd
xlApp.Visible = True
' xlApp.WindowState = xlMaximized '用createobject函数的话这两句要出错
' xlApp.ActiveWindow.WindowState = xlMaximized
Set xlApp = Nothing
ooo:
Unload Me
End
End Sub
Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer
On Error Resume Next
filenum = FreeFile()
Open filename For Input Lock Read As #filenum
Close filenum
errnum = Err
On Error GoTo 0
Select Case errnum
Case 0
IsFileOpen = False
Case 70
IsFileOpen = True
Case Else
Error errnum
End Select
End Function
现在的源码是打开文件所在路径里面的文件,但是无法选择某个文件,
我的要求是打开对话框后选择文件,点击确定就可打开.
还有一个问题是,现在的源码打开excel文件后,蓝色标题被隐藏,应该删除那句代码?
×注(源码中的DLL文件是excel文件伪装的)
9 个解决方案