Jump to content

Recommended Posts

Posted

Hi every one,

I need some help with a sricpt that list user's text files in one directory then opens them with excel.

my problem is that I need the text file to be imported via the Text import wizard.

can some one help please.. :whistle:

Posted

Just make the text file a CSV file.

Then if you open it, it will automatic be devided in colums etc.

This does not work as the user's need to change output via the import wizard, this is the macro code I found, but can not get to work via Auto.

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Sub ImportTextUsingXlDialogOpen()

'\ use this approach to prompt user for text wizard values

Application.ScreenUpdating = False

Application.DisplayAlerts = False

'\ display open file dialog and copy to new (temporary workbook)

'On error resume next - traps for user clicking cancel in the import dialog

'Error number is 1004 - is so exit the procedure

On Error Resume Next

If Application.Dialogs(xlDialogOpen).Show("C:\Magix\*.txt") Then

If Err.Number = 1004 Then

Exit Sub

End If

ActiveSheet.UsedRange.Select '\ select imported text in temporary workbook

Selection.Copy '\ copy to clipboard

ActiveWorkbook.Close '\ close temporary workbook

Worksheets.Add

Range("A1") = "Dialogs(xlDialogOpen) Method"

Range("A2").Select

ActiveSheet.Paste '\ paste text into your workbook

End If

Application.ScreenUpdating = True

Application.DisplayAlerts = True

End Sub

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...