Excel Macro Batch .obj to .xls file

heamarie

New Member
Joined
Apr 20, 2011
Messages
1
Hi all!
I'm working on my first excel Macro and after reading through millions of ppl's posts, I can't seem to find one that will work specifically for me. I'm trying to batch process a number of .obj files (space delimited) by having excel open them in the proper format and then automatically save them as a .xls file with the same name. Here's what I've put together so far from what everyone has posted (below), the only problem is it doesn't name them appropriately, it just says filename, filename1, filename 2 etc..

Sub OpenTextFiles()
Dim sFile As String

With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Directory"
If .Show = 0 Then Exit Sub
End With

Application.DisplayAlerts = False
sFile = Dir("*.obj")
Do While Len(sFile) > 0
Workbooks.OpenText Filename:=sFile, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=True, Semicolon:=False, Comma:=False, _
Space:=True, Other:=False
sFile = Dir()

Set wb = Workbooks(Workbooks.Count)
wb.SaveAs "C:\Users\heather\Desktop\filename" & cnt & ".xls", xlWorkbookNormal

wb.Close

cnt = cnt + 1

Loop
Application.DisplayAlerts = True
End Sub

Any help is greatly appreciated, my obj files are something like 14wfrb, 14wflb, 1932wfrb, etc.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

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