Copying and renaming unopened workbook in excel

2019-07-15 09:15发布

I am trying to copy an entire unopened workbook located at one file path, rename it and save it to a new directory... I am having issues with the renaming and saving, here is my code thus far:

Private Sub new_file_Click()
Dim ActBook As Workbook, NewFile As String
Dim ToolFilePath As String, DestFilePath As String, NewToolName As String
NewToolName = InputBox("Enter the Tool Name.")

MsgBox (Tools_ListBox.Value)
ToolFilePath = GetToolPath(Tools_ListBox.Value)
ToolFilePath = GetPath & ToolFilePath

DestFilePath = GetPath & GetDestPath(Tools_ListBox.Value) & NewToolName & ".xlsm"

Set ActBook = Workbooks.Add(ToolFilePath)
ActBook.SaveAs DestFilePath
ActBook.Close True

The file that i want to copy is located at the path in ToolFilePath and the located I want to rename it to is DestFilePath, which includes the excel .xlsm extension.

Where am I going wrong?

Thanks

标签: excel vba
2条回答
不美不萌又怎样
2楼-- · 2019-07-15 09:53

You can also use the NAME method if you do not wish to retain the original file.

Name ToolFilePath As DestFilePath
查看更多
祖国的老花朵
3楼-- · 2019-07-15 10:04

Why not just use:

FileCopy(ToolFilePath,DestFilePath)

No need to open it.

查看更多
登录 后发表回答