我有一个工作簿,我用作模板来估计当我填写模板时,有一个宏创建一个新工作簿并将模板工作簿的所有工作表复制到新工作簿然后删除我不希望客户看到的所有公式和信息。
这是我的代码的一部分,它创建新工作簿并将所有工作表从模板复制到新工作表然后清理它
[ssh]$ php shell/lucene-tool.php --removeall 1
Removing all documents from the index...(can be slow)
PHP Fatal error: Uncaught exception 'Zend_Search_Lucene_Exception' with message 'Wrong segments.gen file format' in /html/lib/Zend/Search/Lucene.php:266
Stack trace:
0 /html/lib/Zend/Search/Lucene.php(529): Zend_Search_Lucene::getActualGeneration(Object(Zend_Search_Lucene_Storage_Directory_Filesystem))
1 /html/lib/Zend/Search/Lucene.php(211): Zend_Search_Lucene->__construct('/html...', true)
2 /html/app/code/community/Php4u/BlastLuceneSearch/Model/Blastlucenesearch.php(19) : eval()'d code(1) : eval()'d code(1) : eval()'d code(18): Zend_Search_Lucene::create('/chroot/home/wo...')
3 /html/app/code/community/Php4u/BlastLuceneSearch/Model/Blastlucenesearch.php(19) : eval()'d code(1) : eval()'d code(1) : eval()'d code(18): Php4u_BlastLuceneSearch_Model_BlastLuceneSearch->getIndex()
4 /html/shell/lucene-t in /html/lib/Zend/Search/Lucene.php on line 297
我想在保存窗口打开时这样做,它会从单元格A2的文件路径中打开,并从单元格A3填充文件名
如果有帮助,我也可以发送/发布完整的excel文件。
答案 0 :(得分:1)
您可以使用对话框的.InitialFileName
属性。
Dim ws As Excel.Worksheet
Set ws = ActiveWorkbook.Sheets("Sheet1")
Dim oFileDialog As FileDialog
Set oFileDialog = Application.FileDialog(msoFileDialogSaveAs)
With oFileDialog
.Title = "Save File"
.ButtonName = "Ok"
.InitialFileName = ws.Range("A2").Value & "\" & ws.Range("A3").Value
.Show
End With
如果您需要取回保存的名称,可以在.SelectedItems
之后使用.Show
MsgBox (oFileDialog.SelectedItems(1))
注意:强>
在执行此操作之前,您可能希望快速验证A2中的目录是否存在。如果它不存在,它将把它扔进一些用户文件夹。
编辑我不确定你的原因是什么不能保存,可能是excel版本或代码中的其他变量。
由于您拥有路径和名称,您真的需要saveas对话框吗?你可以做到
Workbooks.Add
'Then your code in your template that is modifying the active workbook
'Then save it without the dialog
ActiveWorkbook.SaveAs ws.Range("A2").Value & "\" & ws.Range("A3").Value
'OR
ActiveWorkbook.SaveAs Filename:= ws.Range("A2").Value & "\" & ws.Range("A3").Value
答案 1 :(得分:1)
Application.GetSaveAsFilename method是一个不错的选择。将返回值传递给变量类型var,以便您可以测试取消或关闭。
Dim sFN As Variant
With Worksheets("Sheet6")
sFN = .Range("A1") & Chr(92) & .Range("A2") & Format(Date, "_mm-dd-yy") '<~~ no extension yet
End With
With Application
sFN = .GetSaveAsFilename(InitialFileName:=sFN, _
FileFilter:="Excel Workbook (*.xlsx), *.xlsx," & _
"Macro Workbook (*.xlsm), *.xlsm," & _
"Binary Workbook (*.xlsb), *.xlsb")
End With
Select Case sFN
Case False
'user clicked Cancel or Close (×)
Debug.Print sFN
Case Else
With ThisWorkbook
Select Case Right(sFN, 5)
Case ".xlsx"
.SaveAs Filename:=sFN, FileFormat:=xlOpenXMLWorkbook
Case ".xlsm"
.SaveAs Filename:=sFN, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Case ".xlsb"
.SaveAs Filename:=sFN, FileFormat:=xlExcel12
Case Else
'there really shouldn't be a case else
End Select
End With
End Select
我为Select Case statement添加了Workbook.SaveAs method语句到三种常见类型的Excel工作簿。