⑴ 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"