导航:首页 > 文件目录 > vba用户窗体拖放文件路径

vba用户窗体拖放文件路径

发布时间:2023-05-15 08:06:40

① 如何用VBA打开选择文件和选择路径的对话框

'注意引用microsoftoffice 10.0 (或以上)object library
'在文件对话框对中返回选择一个文件夹的路径.
Public Function ChooseFolder() As String
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(msoFileDialogFolderPicker)
With dlgOpen
If .Show = -1 Then
ChooseFolder = .SelectedItems(1)End IfEnd With
Set dlgOpen = Nothing
End Function
'--------------------------------------------------------
'在文件对话框对中,选择一个文件。
Public Function ChooseOneFile(Optional TitleStr As String
= 选择你要的文件, Optional TypesDec As String = 所有文件,
Optional Exten As String = *.*) As String
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
With dlgOpen
.Title = TitleStr
.Filters.Clear '清除所有的文件类型.
.Filters.Add TypesDec, Exten
.AllowMultiSelect = False '不能多选.
If .Show = -1 Then
' .AllowMultiSelect = True '多个文件
' For Each vrtSelectedItem In .SelectedItems
' MsgBox Path name: & vrtSelectedItem
' Next vrtSelectedItem
ChooseOneFile = .SelectedItems(1) '第一个文件End IfEnd With

② 如何运用VBA将指定路径下的某一文件复制到另一指定路径下

这种dos命令能缓携完成的操作,直接在VBA里用核散shell执行即可,比纯vba代码省事太多了。详情改哪氏见
excelhome

③ vba如何设置首次打开文件路径

1、首先打开vba,并登录自己的账号。
2、其次选中地址所在单元格,运行下述代码即可打开指定的文件夹。
3、最后选中路径,点击打开即可。

④ VBA如何获取当前EXCEL文件的路径

1、首先打来开Excel数据表,在开发自工具中打开VBA编辑器。

⑤ vba打开文件后如何获得打开文件的路径

S=activeworkbook.Path & "\" & activeworkbook.Name

S=workbooks("test.xls").Path & "\" & workbooks("test.xls").Name

⑥ VBA中怎么通过打开文件的对话框获取选择文件的路径并在其他模块中引用该路径

1.插入一来个模块或在已有的源模块最上面一行定义一个全局变量
比如: Public iFileName As String
2.在这个工作薄的其他模块中都可以引用这个变量

比如:(先执行一次test1,再执行test2)
Sub test1()
'打开一个选择文件的对话框
iFileName = Application.GetOpenFilename
End Sub
Sub test2()
If iFileName = "False" Then
MsgBox "没有选择文件!"
Else
wz = InStrRev(iFileName, "\")
Path = Left(iFileName, wz)
fname = Right(iFileName, Len(iFileName) - wz)
MsgBox "选择的文件名为:" & fname & vbCrLf & "路径为:" & Path
End If
End Sub

⑦ 请问高人 vba中 选择文件的路径,和文件名 放在哪个控件中 怎么实现谢谢你

Sub DateSave()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
ThisWorkbook.Path & "\" & Date & ".xls", _
FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
Application.DisplayAlerts = True
End Sub
请将“ThisWorkbook.Path & "\" & Date & ".xls", _”改为“"d:\" & Date & ".xls", _”,其中“"d:\" ”就是你要存的路径。
希望我的回答对你有所帮助。

⑧ VBA中怎样实现当一个文件用鼠标拖到From界面的文本框中的时候,把文件名显示在文本框中并记录它的路径

在窗体上添加如下控件各1个:
DriveListBox --- 驱动器列表
DirListBox ---- 文件夹列表
FileListBox ---- 文件列表
TextBox ---- 文本框
CommandButton ---- 命令按钮
完整代码如下:
Option Explicit

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_GotFocus()
OldDrive = Drive1.Drive
End Sub

Private Sub File1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
File1.Drag 1
End Sub

Private Sub File1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
File1.Drag 2
End Sub

Private Sub Drive1_Change()
Dim msg As String, title As String
Dim style, response

On Error GoTo ErrorNum1
Dir1.Path = Drive1.Drive
Exit Sub

ErrorNum1:
msg = "驱动器没有准备好!" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
"或者磁神派盘损坏。"
style = vbRetryCancel + vbCritical + vbDefaultButton1
title = "错误"
response = MsgBox(msg, style, title)
If response = vbRetry Then
Resume
Else
Drive1.Drive = OldDrive
Exit Sub
End If

End Sub

Private Sub Form_Load()
File1.Pattern = "*.TXT"
File1.Path = Dir1.Path
End Sub

Private Sub Text1_DragDrop(Source As Control, X As Single, Y As Single)
Dim MyLineStr As String
Dim TextStr As String
Dim MyFileN As Long
MyFileN = FreeFile
TextStr = ""
Open Dir1.Path & "\" & File1.FileName For Input As #MyFileN ' 打开文件。
Do While Not EOF(MyFileN) ' 循环至文件尾。
Line Input #1, MyLineStr ' 读入一行数据并将其赋予某变量。
TextStr = TextStr & MyLineStr & Chr(13) & Chr(10)
Loop
Close #1 ' 关闭文件脊瞎早樱雀。
Text1.Text = TextStr
End Sub

⑨ 如何通过VBA,获得本文件所在的文件夹路径。

Subs()
Dimpth$
pth=ThisWorkbook.Path
MsgBox"本文件的路径为:"&pth
EndSub

⑩ 如何运用VBA将指定路径下的某一文件复制到另一指定路径下

1、首先打开工作表凳正空,点击【开发工具】下的【Visual Basic 】选项。

阅读全文

与vba用户窗体拖放文件路径相关的资料

热点内容
java第一份工作影响 浏览:595
指示的文件系统找不到数据库目录 浏览:504
java3des和net对接 浏览:668
怎么在家上网编程 浏览:909
订阅已关为什么还显示app 浏览:169
大华详细教程 浏览:901
学信网是一种什么网站 浏览:378
wow插件文件夹 浏览:302
c源程序文件的缺省扩展名为 浏览:952
java类类型 浏览:971
拼多多关键词数据怎么下载 浏览:867
哪个app可以买火影忍者号 浏览:524
2012r2添加数据库引擎 浏览:549
贷款app如何注销 浏览:966
懒人版本lol 浏览:195
ipad怎么新建文件夹 浏览:697
wps文字密码暴力破解软件 浏览:68
51单片机ds1302程序 浏览:973
学编程方面需要哪些优势 浏览:675
电脑太大的文件怎么上传微信 浏览:514

友情链接