导出到复制的文件

Export into a copied file

我会先告诉你我想做什么,也许这样更容易找到解决方案。我想将一个文件(更改后)导出到一个单独使用宏按钮等的文件中。问题是我无法删除所述文件。

我目前的解决方案如下:我使用 "open file" 对话框,因此用户告诉我应该用作模板的 Excel。 VBA 然后应该复制这个文件(目标再次由保存文件对话框给出)然后删除新文件中使用的范围并复制这个新文件中的值。

所以涉及到3个文件。

到目前为止,我有这段代码可以打开 B 并复制它(我猜)。我的主要问题是现在如何访问新创建的文件。我假设我可以以某种方式将它存储为变量。像 X = Path the user just selected in the save file dialog 这样的东西? 之后删除和插入数据应该是相当简单的我guess/hope.

我希望你们能帮助我并提前致谢:)

到目前为止,这是我的代码:

Dim StandardPfad As String
Dim ExportBlatt As Worksheet
Dim NeueDatei As Workbook


StandardPfad = "C:\XYZ"

'   ExportBlatt = Worksheets("Blatt1")

Set NeueDatei = Workbooks.Add
ThisWorkbook.Sheets("Blatt1").Copy Before:=NeueDatei.Sheets(1)
Application.DisplayAlerts = False
Sheets(2).Delete
Application.DisplayAlerts = True

' displays the save file dialog
StandardPfad = Application.GetSaveAsFilename(FileFilter:= _
        "Exceldateien (*.xlsx), *.xlsx", Title:="Vorlagen Datei auswählen", _
        InitialFileName:="")

NeueDatei.SaveCopyAs Filename:="C:\Test\CopyBook.xls" 'Hier Speicherort angeben

NeueDatei.Close savechanges:=False

要么我在你的问题中遗漏了什么,要么...这 StandardPfad 还不够吗?

如果用户取消选择,它需要更多的错误处理,但那是你的 X = Path the user just selected in the save file dialog

' displays the save file dialog
StandardPfad = Application.GetSaveAsFilename(FileFilter:= _
    "Exceldateien (*.xlsx), *.xlsx", Title:="Vorlagen Datei auswählen", _
    InitialFileName:="")

NeueDatei.SaveCopyAs Filename:=StandardPfad