我正在使用以下代码来添加新工作簿,保存并命名工作簿(基于位于工作表中某个单元格中的日期)。

Dim wb As Workbook
Dim wbName As String
wbName = ThisWorkbook.Sheets("Sheet1").Range("M145").value


    fName = Application.GetSaveAsFilename(wbName)
    If fName = False Then
        MsgBox "Publish couldn't be completed since you didn't choose where to save the file."
        Exit Sub
    Else
        Set wb = Workbooks.Add
        wb.SaveAs (fName)
    End If

但似乎每当单元格“M145”包含点(“.”)如“31.3.16”时,我的文件名不会出现在 SaveAs 提示中,我看到一个没有
任何错误信息。

我不认为这与它有任何关系,但我的工作表是从右到左的。有没有人知道如何解决这个问题?

最佳答案

虽然我无法复制该错误,但使用 FileDialog 对象可能会更好:

Dim wb As Workbook
Dim wbName As String
Dim fdlg As FileDialog

wbName = ThisWorkbook.Sheets("Sheet1").Range("M145").value

Set fdlg = Application.FileDialog(msoFileDialogSaveAs)
With fdlg
    .InitialFileName = wbName
    .Show
    Set wb = Workbooks.Add
    On Error Resume Next 'Suppress any errors due to invalid filename, etc.
    wb.SaveAs(fdlg.SelectedItems(1))
    If Err.Number <> 0 Then
        MsgBox "Publish couldn't be completed since you didn't choose where to save the file."
        wb.Close False  'Get rid of the workbook since it's not being saved
        Exit Sub
    End If
    On Error GoTo 0 'Resume normal error handling
End With

关于vba - SaveAs 不接受 Excel VBA 中包含 "."的字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36320580/

10-11 06:24