Error - macro save as xlxs

nasire

New Member
Joined
Sep 22, 2017
Messages
5
Dear all,

it's the first time i'm using a macro in excel and i don't know VBA very well, yet. I need to save all files in some different folders from .dta to .xlxs. I opened the first file and create a new macro in the folder 'PERSONAL.xlsb' and tried with this program:

Sub m()



Dim sFileName As Str


sFileName = Dir(ActiveWorkbook.Path & "*.dta*")

Do While (Len(sFileName) > 0)

ActiveWorkbooks.SaveAs sFileName, xlsx
ActiveWorkboos.Close
sFileName = Dir
Loop

End Sub

But I visualize an error message that I try to translate in english:"compilation error user-defined type not defined".

After reading some posts, I checked 'Microsoft Visual Basic for Applications.....' in References, from Tools Menu but I'm having the same error.

Could you please help me to solve this issue?

Thanks,
Irene
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You've got a typo on this line
Code:
ActiveWorkboos.Close
You're missing a k. Amongst other things
That said you're not actually opening any of the files.

Untested but try
Code:
Sub m()

    Dim sFileName As String
    
    
    sFileName = Dir(ActiveWorkbook.Path & "*.dta*")
    
    Do While (Len(sFileName) > 0)
        Workbooks.Open sFileName
        ActiveWorkbook.SaveAs sFileName, FileFormat:=51
        ActiveWorkbook.Close
    sFileName = Dir
    Loop

End Sub
 
Last edited:
Upvote 0
Thanks for your quickly answer :)

Yes, I was trying to do it without opening...like a sort of 'external' conversion but I think it's not possible.

By the way, I don't have any message error now but nothing happens when I run the macro...
 
Upvote 0
I missed a bit. Try this
Code:
Sub m()

    Dim sFileName As String
    
    
    sFileName = Dir(ActiveWorkbook.Path & "\*.dta*")
    
    Do While (Len(sFileName) > 0)
        Workbooks.Open sFileName
        ActiveWorkbook.SaveAs sFileName, FileFormat:=51
        ActiveWorkbook.Close
    sFileName = Dir
    Loop

End Sub
 
Upvote 0
Are there files in the same folder as the active workbook
 
Upvote 0
I mean there are only .dta original files in the folder, even after launch the macro. Do you think they are saved in some other folder probably?
 
Upvote 0
For the macro to work you need to open one of the files in the folder & then run the macro
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
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