Copy Worksheet from .xlsx Workbook to .xls Workbook

mackc557

Board Regular
Joined
Nov 3, 2021
Messages
125
Office Version
  1. 2019
Platform
  1. Windows
I know that a normal worksheet.copy from a .xlsx workbook to a .xls workbook causes an error. Is there anyway to convert the sheet as it's being copied or crop the sheet (I only need about $A$1:$J$50)? I know I can create a new sheet, rename it, paste the data, and lock it; however I'd like to see if the conversion is possible.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Not when you copy. But you can do it when you save.
VBA Code:
Sub TestCopy()
    Dim WB As Workbook
    Dim WS As Worksheet
    Dim FilePath As String
    
    Set WS = ActiveSheet
    
    FilePath = CurDir & "\Test.xls"
    
    WS.Copy
    Set WB = ActiveWorkbook
    Debug.Print WB.FileFormat
    
    Application.DisplayAlerts = False
    WB.SaveAs Filename:=FilePath, FileFormat:=xlExcel8
    Application.DisplayAlerts = True
    
    Debug.Print WB.FileFormat
    WB.Close False
End Sub
 
Upvote 0
Not when you copy. But you can do it when you save.
VBA Code:
Sub TestCopy()
    Dim WB As Workbook
    Dim WS As Worksheet
    Dim FilePath As String
   
    Set WS = ActiveSheet
   
    FilePath = CurDir & "\Test.xls"
   
    WS.Copy
    Set WB = ActiveWorkbook
    Debug.Print WB.FileFormat
   
    Application.DisplayAlerts = False
    WB.SaveAs Filename:=FilePath, FileFormat:=xlExcel8
    Application.DisplayAlerts = True
   
    Debug.Print WB.FileFormat
    WB.Close False
End Sub

Thank you for this. I did go about just copying the range to a new sheet.

The issue was I had some workbooks already saved in the .xls format, but I was trying to programmatically copy a worksheet from a workbook already saved in .xlsx format.

Final solution; just copy the range to a new sheet.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top