2
回答
Name sFileName As sFileNameBackup
滴滴云服务器,限时包月0.9元,为开发者而生>>>   

@肖老师 你好,想跟你请教个问题:

 Name sFileName As sFileNameBackup

这一句什么意思啊?貌似VB语法中找不到这样的句型


<无标签>
举报
leo1985
发帖于5年前 2回/43阅
共有2个答案 最后回答: 5年前

文件重命名,看看这个,应该对你有帮助。

2 Ways Of Renaming A File In VBA

Written by Joel T. Protusada for Pro-business Excel VBA Programming

Sometimes in your business application programming using VBA, you'll find yourself in a situation wherein you need to rename a file. Macro Recording at this point will not be helpful as you cannot do the renaming in Excel interactivity. Here are two ways of doing it at a VBA level:

Sub DoRename()
Name "c:\test.xls" As "c:\test2.xls"
End Sub

Another way of doing it is by using the CreateObject function:

Sub DoRename()
Dim fso As Object
Set fso =  CreateObject("Scripting.FileSystemObject")
fso.MoveFile "c:\test.xls", "c:\test2.xls"
Set fso = Nothing
End Sub

Another function of this two routines is that it can be used to move a file from folder to another. Here are examples:

Sub DoMove()
Name "c:\folder1\test.xls" As "c:\folder2\test.xls"
End Sub

Moving a file using CreateObject function:

Sub DoRename()
Dim fso As Object
Set fso =  CreateObject("Scripting.FileSystemObject")
fso.MoveFile "c:\folder1\test.xls", "c:\folder2\test.xls"
Set fso = Nothing
End Sub
顶部