复制和重命名未打开的工作簿在excel [英] Copying and renaming unopened workbook in excel

查看:86
本文介绍了复制和重命名未打开的工作簿在excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制位于一个文件路径的整个未打开的工作簿,重命名并将其保存到新目录中...我有重命名和保存的问题,这里是我的代码到目前为止:

  Private Sub new_file_Click()
Dim ActBook作为工作簿,NewFile As String
Dim ToolFilePath As String,DestFilePath As String ,NewToolName As String
NewToolName = InputBox(输入工具名称)

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

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

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

我要复制的文件位于ToolFilePath中的路径,我想将其重命名为DestFilePath,其中包含excel .xlsm扩展名。



我在哪里出错?



谢谢

解决方案

为什么不使用:

  FileCopy(ToolFilePath,DestFilePath)

无需打开它。


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

解决方案

Why not just use:

FileCopy(ToolFilePath,DestFilePath)

No need to open it.

这篇关于复制和重命名未打开的工作簿在excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆