简体   繁体   English

为什么VBA在ActiveWorkbook.SaveAs上创建一个文件夹

[英]Why is VBA creating a folder on ActiveWorkbook.SaveAs

I have this VBA: 我有这个VBA:

ActiveWorkbook.SaveAs Filename:=Path & Filename & ".xls"
ActiveWorkbook.Close

This is supposed to save the currently active workbook or worksheet to a path and file name provided. 这应该将当前活动的工作簿或工作表保存到提供的路径和文件名。 The extension ".xls" is used so that the exported file is a Excel 97-2003 Workbook. 使用扩展名“.xls”,以便导出的文件是Excel 97-2003工作簿。

It saves the Workbook or Worksheet but has a folder included in them. 它保存工作簿或工作表,但包含一个文件夹。 Let's say the file name was "Master.xls", ActiveWorkbook.SaveAs works but the VBA seem to include a folder named "Master_files" next to it as if it were saved as a web file. 假设文件名是“Master.xls”, ActiveWorkbook.SaveAs可以工作,但VBA似乎在它旁边包含一个名为“Master_files”的文件夹,就好像它被保存为Web文件一样。 How can I disable this? 我怎么能禁用它?

Note that the sheet came from an online database, when I click the link to export the records into an Excel sheet it doesn't download it but instead opens it straight from web to my Excel application which is why I created this SaveAs code. 请注意,该工作表来自在线数据库,当我单击链接将记录导出到Excel工作表时,它不会下载它,而是直接从Web打开它到我的Excel应用程序,这就是我创建此SaveAs代码的原因。

I believe you need to expressly specify the format: 我相信你需要明确指定格式:

ActiveWorkbook.SaveAs Filename:=Path & Filename & ".xls", FileFormat:=xlExcel8

Otherwise, it is saving as HTML, along with the _files , because you got it from the Web (I think). 否则,它将与_files一起保存为HTML,因为您是从Web获取的(我认为)。 MSDN says: MSDN说:

For an existing file, the default format is the last file format specified 对于现有文件,默认格式是指定的最后一种文件格式

which I am guessing is HTML for your situation. 我猜的是你的情况的HTML。

xlExcel8 is the constant to use for .xls files per Ron de Bruin's reference . xlExcel8是每个Ron de Bruin参考的 .xls文件使用的常量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM