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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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