宏保存电子表格需要重新打开excel文件后恢复尝试

yptwkmov  于 2023-05-08  发布在  其他
关注(0)|答案(1)|浏览(205)

我一直在建立一个Excel表格,让我的员工填写。形式主要是信息收集。我在后台做了一些宏检查,以确保一切都完成。我已经重新使用了一个保存宏从以前的excel宏和目前得到一个错误,我不知道是什么原因造成的。保存并重新打开文档后,将显示此错误消息

保存宏以前工作过,唯一的区别是我的新宏在“本工作簿”和“工作表1”中有VB代码,而不是模块。我的问题是,是什么导致了这个错误?是我的保存功能还是我的宏的设置?

If SaveLocations <> vbNullString Then
        If Right(SaveLocations, 1) <> "\" And 
        InStr(Right(SaveLocations, 10), ".") = 0 Then
            SaveLocations = SaveLocations & "\"
        Else
        End If
        
        If FileFormatValue = 51 Then
            MacroWb.SaveAs Filename:=SaveLocations & RFC_FileName & _ 
            ".xlsx", _
            FileFormat:=FileFormatValue, CreateBackup:=False
        Else
            MacroWb.SaveAs Filename:=SaveLocations & RFC_FileName & 
            ".xlsm", _
            FileFormat:=FileFormatValue, CreateBackup:=False
        End If
    Else
        fname = Application.GetSaveAsFilename(InitialFileName:="", _ 
        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:=2, Title:="Save Report To...")
        
        If fname <> False Then
            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 FileFormatValue = 0 Then
                MsgBox "Sorry, unknown file extension."
            Else
                ActiveWorkbook.SaveAs Filename:=fname, _ 
                FileFormat:=FileFormatValue, CreateBackup:=False
            End If
        Else
        End If
    End If

I didn't know how to exactly search for this error, but thought this community would have some suggestions.  Thanks in Advance.
0yg35tkg

0yg35tkg1#

我能够确定错误是由于我在文档上的数据验证造成的。解决方法是将下拉列表值保存在列中并引用它,而不是填充它。

相关问题