问题描述
我有一个子文件可以将文档另存为二进制工作簿.(来自堆栈溢出.)
I have a sub to save my doc as a binary workbook. (Got from Stack Overflow.)
我尝试从一个单元格中获取该值作为文件名.
I tried taking the value from a cell to use as the file name.
通常它可以正常工作,我不知道为什么有时不可以.
Usually it works fine, I cannot figure out why sometimes not.
我在O26单元格中的数据始终是文本字符串.
My data in cell O26 is always a text string.
Dim fname As Variant
Dim FileFormatValue As Long
fname = Application.GetSaveAsFilename(InitialFileName:=Range("O26"), filefilter:= _
" Excel Macro Free Workbook (*.xlsx), *.xlsx," & _
" Excel Macro Enabled Workbook (*.xlsm), *.xlsm," & _
" Excel 2000-2003 Workbook (*.xls), *.xls," & _
" Excel Binary Workbook (*.xlsb), *.xlsb", _
FilterIndex:=4, Title:="Save as xlsb")
'Find the correct FileFormat that match the choice in the "Save as type" list
Select Case LCase(Right(fname, Len(fname) - InStrRev(fname, ".", , 1)))
Case "xls": FileFormatValue = 56
Case "xlsx": FileFormatValue = 51
Case "xlsm": FileFormatValue = 52
Case "xlsb": FileFormatValue = 50
Case Else: FileFormatValue = 0
End Select
If fname = isblank Then
MsgBox "Project Not Saved!"
Exit Sub
End If
ActiveWorkbook.SaveAs fname, FileFormat:= _
FileFormatValue, CreateBackup:=False
推荐答案
超越简单!我只需要在Cell O26的文本字符串中添加.xlsb即可!现在,我的扩展名与过滤的扩展名匹配.(O26单元格中的初始值是一个公式,因此添加它并不重要,我只是将其包含在公式中.)
Beyond simple! I just needed to add .xlsb to my text string in Cell O26!Now my extension matches the filtered extension.(The initial value in Cell O26 is a formula, so adding it is not a big deal, I just included it in the formula.)
这篇关于Application.GetSaveAsFilename(InitialFileName:= Range("O26"))有时会出现一个空白对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!