⑴ Excel vba 怎么移动一个文件
下面的代码接着你的4行:
a = a & c
b = b & c
if dir(a)="" then
msgbox "不存在"
else
name a as b
msgbox "已移动"
end if
⑵ 如何运用VBA将指定路径下的某一文件复制到另一指定路径下
这种dos命令能缓携完成的操作,直接在VBA里用核散shell执行即可,比纯vba代码省事太多了。详情改哪氏见
excelhome
。
⑶ 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将指定路径下的某一文件复制到另一指定路径下
1、首先打开工作表凳正空,点击【开发工具】下的【Visual Basic 】选项。
⑸ 如何用VBA复制整个文件夹包括子目录
Sub Files(Path As String, afterPath)
'Path:原文件夹路径;afterPath:目标文件夹路径
Dim Spath As String
Set fs = CreateObject("Scripting.FileSystemObject")
Spath = Dir(Path, vbDirectory)
Do While Len(Spath)
If Spath <> "." And Spath <> ".." Then
fs.CopyFolder Path, afterPath
Spath = Dir()
End If
Loop
End Sub
————————————————
版权声明:本文为CSDN博主「前端小菜鸟007」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_41844140/article/details/103188537
⑹ 如何运用VBA将指定路径下的某一文件复制到另一指定路径下
格式:FileCopy 源文件标识伍裤派纯山符, 目标文件标识符
文件标识符:包含完整的 磁盘、目录、文件名腔贺
例如:
FileCopy "C:\数据文件.txt", "C:\AAA\BBB\数据文件.txt"
⑺ Excel vba如何移动文件到指定的文件夹
Name "原文件夹\文件名" As "指定文件夹\文件名"
⑻ VBA设置已经设置了数据有效性的列的拖放功能
想拖放时,先用代码解密,完成后再冲扒加密友含,即:
Worksheets(Sheet1).Unprotect "888888"
'好判笑这里加入想要的操作
'……
Worksheets(Sheet1).Protect "888888"