Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run time error 1004

Tags:

excel

vba

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:=strPath
like image 707
john Avatar asked Dec 16 '22 12:12

john


1 Answers

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
like image 52
mischab1 Avatar answered Dec 30 '22 11:12

mischab1