1

次のコードabcd.xlsを使用して、ファイルの名前を から に変更しようとしています。xyz.xlsx

  NumOfAttachments = Range("RecCount").Value
  DestinationFolderPath = Range("destinationfolder").Value
  NewShtName = "Sheet1"

  If NumOfAttachments <> 0 Then
    For X = 0 To NumOfAttachments - 1
      OrigName = Range("Startcell").Offset(X, 1).Value
      NewName = Range("startcell").Offset(X, 2).Value
      SourceFolderPath = Range("startcell").Offset(X, 3).Value
      NewFile = DestinationFolderPath & NewName
      If Dir(DestinationFolderPath & OrigName) <> "" Then Kill DestinationFolderPath & OrigName
      FileCopy SourceFolderPath & OrigName, DestinationFolderPath & OrigName

      If Dir(NewFile) <> "" Then Kill NewFile
      Name DestinationFolderPath & OrigName As NewFile

xyz.xlsxこの後、ファイル( )を開こうとすると、次のエラーが表示されます-

excel cannot open the file xyz.xlsx because the file format or file extension is not valid

4

1 に答える 1

10

理由はとても簡単です。正しいファイル形式を使用していません。

コード.SaveAsは次のようになります

.SaveAs "\myserver\test\xyz.xlsx", FileFormat:=51

ファイル形式については、以下の表を参照してください

50 = xlExcel12 (Excel Binary Workbook in 2007-2010 with or without macro's, xlsb)
51 = xlOpenXMLWorkbook (without macro's in 2007-2010, xlsx)
52 = xlOpenXMLWorkbookMacroEnabled (with or without macro's in 2007-2010, xlsm)
56 = xlExcel8 (97-2003 format in Excel 2007-2010, xls)

このリンクをお勧めします

于 2013-04-03T23:33:40.143 に答える