vb 如何实现文件拖动到窗体时将该文件打开
vb如何实现文件拖动到窗体时打开,如拖动一个Excel文件到Excel窗口上时会自动打开该Excel文件...
vb 如何实现文件拖动到窗体时打开,如拖动一个Excel文件到Excel窗口上时会自动打开该Excel文件
展开
2个回答
展开全部
'先把form的OLEDropMode属性设置为1,然后复制下面代码运行,拖拽一个xls文件到form(电脑的有office组件)
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
If LCase(Right(Data.Files(1), 4)) = ".xls" Then
ShellExecute Me.hWnd, "Open", Data.Files(1), "", App.Path, 1
Else
MsgBox "非xls文件:" & Data.Files(1)
End If
End Sub
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
If LCase(Right(Data.Files(1), 4)) = ".xls" Then
ShellExecute Me.hWnd, "Open", Data.Files(1), "", App.Path, 1
Else
MsgBox "非xls文件:" & Data.Files(1)
End If
End Sub
展开全部
Private Sub Form_Load()
Form1.OLEDropMode = 1
End Sub
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Open Data.Files(1) For Binary As #1
'......
End Sub
Form1.OLEDropMode = 1
End Sub
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Open Data.Files(1) For Binary As #1
'......
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |