简体   繁体   English

打开另一个工作簿的另存为对话框

[英]Open saveas dialog box for another workbook

I am currently working on a temporary solution but run into a problem....我目前正在研究临时解决方案,但遇到了问题....

The situation is:情况是:

I have a converter built in Excel, that opens up a XLS File, does some tinkering so the file can be uploaded to an Oracle Database.我有一个内置于 Excel 的转换器,它打开一个 XLS 文件,进行一些修改,以便可以将文件上传到 Oracle 数据库。

The problem is, the XLS file I opened I cannot get the Saveas Dialog box to that file, it always saves a copy of the converter instead.问题是,我打开的 XLS 文件无法将 Saveas 对话框保存到该文件,它总是保存转换器的副本。

What I need to happen is to open the Saveas Dialog box in a filepath set the file filter for CSV, for the file that i have opened.我需要做的是在文件路径中打开 Saveas 对话框,为我打开的文件设置 CSV 的文件过滤器。

RRBOOK.Activate The RR Book is the DIM'd file i opened RRBOOK.Activate RR Book 是我打开的 DIM 文件

Dim FileName As String
FileName = Application.GetSaveAsFilename("\\FILEPATH\", FileFilter:="CSV (Comma delimited) (*.csv), *.csv")
If FileName <> "False" Then
 ActiveWorkbook.SaveAs FileName
End If

Any help would be appreciated!任何帮助,将不胜感激!

Avoid using ActiveWorkbook and .Activate .避免使用ActiveWorkbook.Activate

Instead directly save the desired workbook by而是直接保存所需的工作簿

RRBOOK.SaveAs FileName

Also you should specify the file format you wish to save in according to XlFileFormat enumeration and Workbook.SaveAs method .您还应该根据XlFileFormat 枚举Workbook.SaveAs 方法指定要保存的文件格式。

So for saving as CSV you should eg use所以为了保存为 CSV 你应该使用

RRBOOK.SaveAs FileName, xlCSV

So you would end up with something like所以你最终会得到类似的东西

Dim FileName As Variant
FileName = Application.GetSaveAsFilename("\\FILEPATH\", FileFilter:="CSV (Comma delimited) (*.csv), *.csv")
If VarType(FileName) = vbBoolean And FileName = False Then
    'user pressed cancel
    Exit Sub
Else
    RRBOOK.SaveAs FileName
End If

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

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