开发者

Run time error 1004

When trying to run the below I get the following error:

"This extension can not be used with the selected file type. Change the file extension in the file name text box or select a different file type by changing the save as type."

Code:

Dim strPath As String
Dim strFolderPath As String


strFolderPath = "Y:\

strPath = strFolderPath & _
Sheet1.Range("A1").Value & _
Sheet1.Range("B1").Value & ".xlsx"


ActiveWorkbook.SaveAs Filename:=strP开发者_C百科ath


The error means that the ActiveWorkbook is trying to save as a different file format then ".xlsx". To force it to save as .xlsx, you also have to pass the fileformat.

ActiveWorkbook.SaveAs Filename:=strPath, FileFormat:=xlOpenXMLWorkbook


I had the same problem when I was trying to convert a macro enabled workbook (xlsm) into a normal workbook (xlsx)! I finally gave up using the ActiveWorkbook.SaveAs method and used the following code instead:

' Code from http://www.mrexcel.com/forum/excel-questions/516366-saving-xlsm-file-xlsx-using-visual-basic-applications.html#post4478019
sub saveAsXlsx
Dim mySheetList() As String
ReDim mySheetList(0 To (ThisWorkbook.Sheets.Count) - 1)
Dim a As Integer
a = 0
For Each ws In ActiveWorkbook.Worksheets
    mySheetList(a) = ws.Name
    a = a + 1
Next ws

'actually save
Worksheets(mySheetList).Copy
ActiveWorkbook.SaveAs fileName:=flenme 'default ext

The code is originally from here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜