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
vba using save as without opening the file
提问by paulinhax
Is there any way to use ActiveWorkbook.SaveAs
without opening the destination file?
有没有办法在ActiveWorkbook.SaveAs
不打开目标文件的情况下使用?
My main Workbook called TEC ALOC EXT
has 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 EXT
worksheet.
我的主工作簿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 SHEET
sheet.
这对我不利,因为我想不断更改工作TEC ALOC SHEET
表上的内容。
Is there any way to just save the ALOCACAO TECNICOS
without 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 AfterSave
event:
这是由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 库并告诉您一些有关方法的信息。应该给你足够的开始