bulrush
03-21-2011, 04:21 AM
This is a macro which saves the current spreadsheet tab as a tab delimited file with an extension of ".dat". It does not work in 2010. How can I convert it to work in 2010?
Dim wb As Workbook
Dim s As String
Set wb = Application.ActiveWorkbook
s = wb.FullName ' <== Error is here
s = Replace(s, ".xls", ".dat")
ActiveWorkbook.SaveAs Filename:=s, FileFormat:=xlText, CreateBackup:=False
MsgBox "Saved tab-delim file as " & s
Thanks.
DCrake
03-21-2011, 04:26 AM
2007 & 2010 extensions are 4 digits long xlsx therefore you dat file would endup as .datx
change your replace to include xlsx,dat
bulrush
03-21-2011, 05:30 AM
Nope. The open worksheet is actually .xls. I must have edited my question after you posted. The error I get is in the below line: "Object not set" I think was the error.
s=wb.Fullname ' <== Error here
Also, I may be opening .XLS or .XLSX workbooks. In either case, that is not my problem. The problem is with the wb object.
EDIT:
I double checked Excel 2010 help and the Application does support the ActiveWorkbook property, but when I run the macro I get an error "438: object doesn't support the property or method."
Do I have to check my VBA references? If so, which reference to I want to enable/check?
Under Code Window, Tools, References, these references are checked:
Visual Basic for Applications
Microsoft Excel 14.0 Object library (this is for 2010)
OLE Automation
Microsoft Office 14.0 Object Library (this is for 2010)
bulrush
03-21-2011, 05:43 AM
Well, here's my workaround. Apparently E2010 doesn't like the wb variable defined as a Workbook.
'Dim wb As Workbook
Dim s As String
'Set wb = Application.ActiveWorkbook ' No longer valid in E2010.
s = Application.ActiveWorkbook.FullName
s = Replace(s, ".xlsx", ".dat")
s = Replace(s, ".xls", ".dat")
ActiveWorkbook.SaveAs Filename:=s, FileFormat:=xlText, CreateBackup:=False
MsgBox "Saved tab-delim file as " & s