Workbook.save - "The following functions cannot be saved in workbooks without macro photography ..."

My sub opens the .xlsm file in a new instance of Excel, makes changes to the file, and saves the changes.

However, even though the file being opened is .xlsm, after workbook.save I get the warning message "The following functions cannot be saved in workbooks with macroblocks ..."

It doesn't make sense to me because the file is .xlsm. Any ideas?

Edit: I believe I have found the source of the problem. Although the path variable contains C: \ file.xlsm, wkb.path is empty. (see Debug.print below). Why is wkb.path empty?

    Set XL = New Excel.Application
    XL.Visible = False

    For Each Path In XLSMPaths

        Set wkb = XL.Workbooks.Add(Path)

        Debug.Print Path      ' "C:\file.xlsm" 
        Debug.Print wkb.path  ' ""
        Debug.print wkb.name  ' "file"      

        wkb.Save   '<- alert message "The following features cannot be saved in macro-free workbooks..."

    Next Path

      

+3


source to share


1 answer


By default the .save method will save the file as .xls or .xlsx (depending on your excel version), you need to force this with .saveas

wkb.SaveAs Filename:=MyNewPathFilename, FileFormat:=xlOpenXMLWorkbookMacroEnabled

      



obviously change the variable "MyNewPathFilename" to whatever you want to store in the file, maybe you want to move the Path and check if it ends with .xlsm and then pass it to that variable

+5


source







All Articles