文件管理 · 2022年9月7日

vb里选择文件打开|VB弹出打开对话框选择文件

❶ vb6.0中选择的文件怎样打开

Private Sub Command1_Click()Shell "explorer.exe /select,C:\test\123.txt ", vbNormalFocus End Sub

❷ VB弹出打开对话框,选择文件

'添加一个CommonDialog控件'通用声明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 LongConst SW_SHOW = 5'按钮事件Private Sub Command1_Click() On Error GoTo userCanceled With CommonDialog1 .CancelError = True .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks .Filter = "excel文件(*.xls)|*.xls" .ShowOpen ShellExecute Me.hwnd, "open", .FileName, "", "", SW_SHOW End WithuserCanceled:End Sub

❸ 在VB中加入“文件——打开”功能

启动VB,在窗体上画一个TEXTBOX,MultiLine属性设为True,ScrollBars属性设为2。点击“工具”–“菜单编辑器”,在标题中输入“文件(&F)”,在名称中输入“Fi”,再点击“下一个”,点一下向右的箭头,在标题中输入“打开(&O)”,在名称中输入“Op”,点确定,至此菜单的工作完成。下面加入通用对话框:点“工程”–“部件”,从中找到“Microsoft Common Dialog Control 6.0”,把前面的方框内打上勾,点“关闭”。在窗体上画一个刚添加的通用对话框控件。下面开始写代码:单击窗体上的“文件”,选“打开”,这时会跳出代码框。在其中输入:Dim FileName0 As String, FileText As String, R As StringCommonDialog1.DialogTitle = "打开文件"CommonDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"CommonDialog1.ShowOpen '打开对话框FileName0 = CommonDialog1.FileNameIf FileName0 = "" Then Exit SubOpen FileName0 For Input As #1Do While Not EOF(1)Line Input #1, FileTextR = R + FileText & Chr(13) + Chr(10)LoopText1.Text = RClose #1好了,你可以成功了。

❹ vb怎样操作控制“打开对话框”选择文件

CommonDialog 控件(“打开”、“另存为”对话框)通过使用 CommonDialog 控件的 ShowOpen 和 ShowSave 方法可显示“打开”和“另存为”对话框。两个对话框均可用以指定驱动器,目录,文件扩展名和文件名。除对话的标题不同外,另存为对话外观上与打开对话相似。在运行时,当用户选择一个文件“关闭”对话框时,FileName 属性既为选定的文件名。可以设置 Filter 属性,这样对话就只显示某种文件类型,如文本文件。Flags 属性可用来改变对话的元素,当诸如覆盖文件之类的动作发生时,还可用来提示用户。CommonDialog 控件(“打开”、“另存为”对话框)示例下例显示“打开”对话框然后在信息框中显示所选的文件名:Private Sub Command1_Click() ' 设置“CancelError”为 True CommonDialog1.CancelError = True On Error GoTo ErrHandler ' 设置标志 CommonDialog1.Flags = cdlOFNHideReadOnly ' 设置过滤器 CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files" & _ "(*.txt)|*.txt|Batch Files (*.bat)|*.bat" ' 指定缺省的过滤器 CommonDialog1.FilterIndex = 2 ' 显示“打开”对话框 CommonDialog1.ShowOpen ' 显示选定文件的名字 MsgBox CommonDialog1.FileName Exit Sub ErrHandler: ' 用户按了“取消”按钮 Exit SubEnd Sub

❺ vb中,怎样在文本控件中打开任意一个文本文件(路径由其他控件选取)

大概思路打开该文件,读取该文件,写入相应的控件中。希望对你有帮助不清楚再联系吧~

❻ VB中如何打开自己指定类型的文件

PrivateDeclareFunctionShellExecuteLib"shell32.dll"Alias"ShellExecuteA"(ByValhwndAsLong,ByVallpOperationAsString,ByVallpFileAsString,ByVallpParametersAsString,ByVallpDirectoryAsString,ByValnShowCmdAsLong)AsLongPrivateConstSW_SHOW=5PrivateSubForm_Load()ShellExecuteMe.hWnd,"open","C:\User.doc",vbNullString,vbNullString,SW_SHOWEndSub把上面的"C:\User.doc"改成你要打开的文件,还可以是网址或E-mail。这个是用默认的程序打开已知类型的文件。还能打开网址,E-mail地址。

❼ vb程序中怎样用对话框选择需要打开的文件

也可以使用DirListBox、FileListBox和DriveListBox这几个控件各一个

PrivateSubDir1_Change()

File1.Path=Dir1.Path

EndSub

PrivateSubDrive1_Change()

Dir1.Path=Drive1.Drive

EndSub

其中filelistbox的pattern属性用于过滤文件扩展名,设为*.XLS,表示选择XLS文件

再用SETXLBOOK=XLAPP。WORKBOOKS.OPEN(""&Dir1.Path&""&File1.FileName&"")

打开的。改的测试语句如下:

Private Sub Command1_Click()Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象'Set xlBook = xlApp.Workbooks.Open("D:TEST.xls") '打开已经存在的EXCEL工件簿文件Set xlBook = xlApp.Workbooks.Open("" & Dir1.Path & "" & File1.FileName & " ")xlApp.Visible = True '设置EXCEL对象可见(或不可见)Set xlsheet = xlBook.Worksheets("sheet1") '设置活动工作表'Set xlBook = xlApp.Workbooks.Open("D:TEST.xls") '怎样把这一句改成在系统中选择文件,而不是直接打开指定的文件End Sub

❽ vb怎么打开文件夹

1、点击对话框下菜单,点击打开文件对话框。

❾ 如何VB中打开文件

我不知道你是否只需要打开文件还是需要对文件进行其他操作,如下是打开文件的的方法:Option ExplicitPrivate 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 '首先利用API中的ShellExecute函数,使用此函数可打开任意后缀名的文件Private Sub Command1_Click()ShellExecute Me.hwnd, "open", "D:\123.txt", vbNullString, vbNullString, vbNormalFocus ‘具体打开指定目录的文件End Sub附ShellExecute函数说明:VB声明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说明 查找与指定文件关联在一起的程序的文件名返回值Long,非零表示成功,零表示失败。会设置GetLastError参数表参数类型及说明hwndLong,指定一个窗口的句柄,有时候,windows程序有必要在创建自己的主窗口前显示一个消息框lpOperationString,指定字串“open”来打开lpFlie文档,或指定“Print”来打印它lpFileString,想用关联程序打印或打开一个程序名或文件名lpParametersString,如lpszFlie是可执行文件,则这个字串包含传递给执行程序的参数lpDirectoryString,想使用的完整路径nShowCmdLong,定义了如何显示启动程序的常数值。参考ShowWindow函数的nCmdShow参数