vba vba使用另存为而不打开文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45242234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:56:51  来源:igfitidea点击:

vba using save as without opening the file

excelvbaexcel-vba

提问by paulinhax

Is there any way to use ActiveWorkbook.SaveAswithout opening the destination file?

有没有办法在ActiveWorkbook.SaveAs不打开目标文件的情况下使用?

My main Workbook called TEC ALOC EXThas a code to when it's saved it's generate another file without macros in a different path (using FileFormat:=51) called ALOCACAO TECNICOS. But this type of FileFormat also opens the destination file (ALOCACAO TECNICOS) at the end and closes the TEC ALOC EXTworksheet.

我的主工作簿TEC ALOC EXT有一个代码,当它被保存时,它会在不同的路径(使用FileFormat:=51)中生成另一个没有宏的文件,名为ALOCACAO TECNICOS. 但是这种类型的 FileFormat 最后也会打开目标文件 ( ALOCACAO TECNICOS) 并关闭TEC ALOC EXT工作表。

This it not good for me because I want to keep changing things on my TEC ALOC SHEETsheet.

这对我不利,因为我想不断更改工作TEC ALOC SHEET表上的内容。

Is there any way to just save the ALOCACAO TECNICOSwithout opening it?

有没有办法ALOCACAO TECNICOS不打开就保存?

Here is my code:

这是我的代码:

Sub CopiarNovaPlanilha()

Application.EnableEvents = False
Application.DisplayAlerts = False

ActiveWorkbook.SaveAs "I:\CGP\DEOPEX - Supervis?o - Aloca??o das equipes\Consulta Alocados\ALOCACAO TECNICOS", FileFormat:=51

ActiveWorkbook.Sheets(1).Name = "FUNCIONARIOS"


Application.EnableEvents = True
Application.DisplayAlerts = True

End Sub

That is triggered by AfterSaveevent:

这是由AfterSave事件触发的:

Private Sub Workbook_AfterSave(ByVal Success As Boolean)

If Success Then


Call CopiarNovaPlanilha


End If

End Sub

回答by Subodh Tiwari sktneer

One way is this...

一种方法是这样...

Sub CopiarNovaPlanilha()

Application.EnableEvents = False
Application.DisplayAlerts = False

ActiveWorkbook.Sheets.Copy
ActiveWorkbook.SaveAs "I:\CGP\DEOPEX - Supervis?o - Aloca??o das equipes\Consulta Alocados\ALOCACAO TECNICOS", FileFormat:=51
ActiveWorkbook.Sheets(1).Name = "FUNCIONARIOS"


Application.EnableEvents = True
Application.DisplayAlerts = True

End Sub

回答by wrslphil

Here's a website that should help you to accomplish what you need by using the FileSystemObject library. This will enable you to copy from one location to another without actually opening files as such.

这是一个网站,可以帮助您使用 FileSystemObject 库完成所需的工作。这将使您能够从一个位置复制到另一个位置,而无需实际打开文件。

The fist link will show you how to set up excel to use this.

第一个链接将向您展示如何设置 excel 以使用它。

http://www.wiseowl.co.uk/blog/s210/filesystemobject.htm

http://www.wiseowl.co.uk/blog/s210/filesystemobject.htm

This link will describe in more detail about the FSO library and tell you a bit about the methods. Should give you enough to get started

此链接将更详细地介绍 FSO 库并告诉您一些有关方法的信息。应该给你足够的开始

http://www.wiseowl.co.uk/blog/s212/files-folders-vba.htm

http://www.wiseowl.co.uk/blog/s212/files-folders-vba.htm