Save as...

whitoulias

Board Regular
Joined
Jun 22, 2012
Messages
153
Code:
Sub Opendat()
Dim MyFolder As String
On Error GoTo Errorcatch
Dim MyFile As String
MyFolder = "C:\Documents and Settings\Xxxxx\Desktop\" 'put your folder here
MyFile = Dir(MyFolder & "\*.dat")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile
MyFile = Dir
Loop
ActiveWorkbook.SaveAs "report1", FileFormat:=xls, CreateBackup:=False

Errorcatch:
MsgBox Err.Description

End Sub

I have a .dat file which i open with the above code
The above code is run by another xls
The problem is that when i try to save the new xls i get the following message

Method 'Save as' of object '_Workbook' failed

Any ideas

THX
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
ry

Code:
ActiveWorkbook.SaveAs Filename:="report1.xls", FileFormat:=xlExcel8, CreateBackup:=False
 
Upvote 0
This worked fine for me

Code:
Sub Opendat()
Dim MyFolder As String
On Error GoTo Errorcatch
Dim MyFile As String
MyFolder = "C:\Test" 'put your folder here
MyFile = Dir(MyFolder & "\*.dat")
Do While MyFile <> ""
    Workbooks.Open Filename:=MyFolder & "\" & MyFile
    MyFile = Dir
Loop
ActiveWorkbook.SaveAs Filename:=MyFolder & "\report1.xls", FileFormat:=xlExcel8, CreateBackup:=False
Errorcatch:
MsgBox Err.Description

End Sub
 
Upvote 0
This worked fine for me

Code:
Sub Opendat()
Dim MyFolder As String
On Error GoTo Errorcatch
Dim MyFile As String
MyFolder = "C:\Test" 'put your folder here
MyFile = Dir(MyFolder & "\*.dat")
Do While MyFile <> ""
    Workbooks.Open Filename:=MyFolder & "\" & MyFile
    MyFile = Dir
Loop
ActiveWorkbook.SaveAs Filename:=MyFolder & "\report1.xls", FileFormat:=xlExcel8, CreateBackup:=False
Errorcatch:
MsgBox Err.Description

End Sub

I wish i could say the same thing

I tried to do it manually to see what happens. It seems that when making 'save as' manually the name of the file appears like this "filename.dat" and when i choose to save it as xls, excel is not capable of saving it as xls but as .dat
 
Upvote 0
Try recording a macro when using Save AS and changing the Save As Type to .xls
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,470
Latest member
Subhash Chand

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