• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Pb extension file after creating file with Macro

AlexSH09

New Member
Hello,
I experience an issue when I use the following macro:

Code:
Option Explicit
Sub CButton1_Click()
    Dim NewName As String
    Dim nm As Name
    Dim ws As Worksheet

    If MsgBox("Copy specific sheets to a new workbook" & vbCr & _
    "New sheets will be pasted as values" _
    , vbYesNo, "NewCopy") = vbNo Then Exit Sub

    With Application
        .ScreenUpdating = False
        On Error GoTo ErrCatcher
        Sheets(Array("Detail 1", "Detail 2", "Detail 3", "Detail 4", "Detail 5")).Copy
        On Error GoTo 0

        For Each ws In ActiveWorkbook.Worksheets
            ws.Cells.Copy
            ws.[A1].PasteSpecial Paste:=xlValues
            Application.CutCopyMode = False
            Cells(1, 1).Select
            ws.Activate
        Next ws
        Cells(1, 1).Select
        NewName = InputBox("Please Specify the name of your new workbook", "New Copy")
        ActiveWorkbook.SaveCopyAs ThisWorkbook.Path & "\" & NewName & ".xls"
        ActiveWorkbook.Close SaveChanges:=False
        .ScreenUpdating = True
    End With
    Exit Sub

ErrCatcher:
    MsgBox "Specified sheets do not exist within this workbook"

End Sub

This macro copy paste in value the tabs of my file in a new file and i can chose the name of the file.
When I try to open this new file I obtain this error message:

The file you are trying to open 'name.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?

I can open the file. But the problem is later this file is supposed to be a ready-to-upload file for an application and this application doesn't recognized the file cause the upload doesn't work so I think it comes from this "format" issue.

Would anyone know how to solve this?

Thanks!
 

After saving original workbook as a copy so with same extension,
you must open this copy and use SaveAs method then delete the copy.

Activate the Macro Recorder and save manually as a .xls :
you will get the correct code …
 
Back
Top