Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Import txt file via makro

Hi,

the followin cde imports a txt file to excel:

Private Sub Workbook_Open()

Application.DisplayAlerts = False

'Meldung wird angezeigt

MsgBox "Bitte selektieren Sie die zu ladende Adressdaten-Datei!"
ChDir "\"
ChDrive "G:\"
ChDir "operating\handy\adressdaten"
ZuOeffnendeDatei = Application.GetOpenFilename("Textdateien
(*.txt),*.txt")
If ZuOeffnendeDatei = False Then
Exit Sub
End If
Application.ScreenUpdating = False


Workbooks.OpenText Filename:=ZuOeffnendeDatei, Origin:= _
xlWindows, StartRow:=1, DataType:=xlDelimited, Semicolon:=True _
, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1))

'Herkunftsdatei wird Variable zugewiesen

ZuOeffnendeDatei = ActiveWorkbook.Name

Workbooks(ZuOeffnendeDatei).Activate
Selection.CurrentRegion.Select
Selection.Copy
Workbooks(ZuOeffnendeDatei).Close
Windows("export_outlook.xls").Activate
Sheets("Tabelle1").Select
Range("A1").Select
Selection.PasteSpecial
Selection.Columns.AutoFit
Range("A1").Select

Unfortunately the data in column 4 and 5 are telephone numbers, which will
be incorrectly imported:
a number = 005541995799999 will be shown as 5.542E+11
I tried to set format the columns with number format = "@" in advance, but
it didn't help.

For help thanks in advance,

Regards,
Markus


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Import txt file via makro

Record a macro when you open the file manually.

And when you're in the text to columns wizard, make sure you change the fields
that hold phone numbers to Text (don't leave it general).

Then take that recorded code and insert it into your code.

You'll be changing this section of code:

Workbooks.OpenText Filename:=ZuOeffnendeDatei, Origin:= _
xlWindows, StartRow:=1, DataType:=xlDelimited, Semicolon:=True _
, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1))




Markus Mannheim wrote:

Hi,

the followin cde imports a txt file to excel:

Private Sub Workbook_Open()

Application.DisplayAlerts = False

'Meldung wird angezeigt

MsgBox "Bitte selektieren Sie die zu ladende Adressdaten-Datei!"
ChDir "\"
ChDrive "G:\"
ChDir "operating\handy\adressdaten"
ZuOeffnendeDatei = Application.GetOpenFilename("Textdateien
(*.txt),*.txt")
If ZuOeffnendeDatei = False Then
Exit Sub
End If
Application.ScreenUpdating = False

Workbooks.OpenText Filename:=ZuOeffnendeDatei, Origin:= _
xlWindows, StartRow:=1, DataType:=xlDelimited, Semicolon:=True _
, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1))

'Herkunftsdatei wird Variable zugewiesen

ZuOeffnendeDatei = ActiveWorkbook.Name

Workbooks(ZuOeffnendeDatei).Activate
Selection.CurrentRegion.Select
Selection.Copy
Workbooks(ZuOeffnendeDatei).Close
Windows("export_outlook.xls").Activate
Sheets("Tabelle1").Select
Range("A1").Select
Selection.PasteSpecial
Selection.Columns.AutoFit
Range("A1").Select

Unfortunately the data in column 4 and 5 are telephone numbers, which will
be incorrectly imported:
a number = 005541995799999 will be shown as 5.542E+11
I tried to set format the columns with number format = "@" in advance, but
it didn't help.

For help thanks in advance,

Regards,
Markus


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Import txt file via makro

Thanks Dave,

that helped me!

Regards,
Markus

"Dave Peterson" schrieb im Newsbeitrag
...
Record a macro when you open the file manually.

And when you're in the text to columns wizard, make sure you change the
fields
that hold phone numbers to Text (don't leave it general).

Then take that recorded code and insert it into your code.

You'll be changing this section of code:

Workbooks.OpenText Filename:=ZuOeffnendeDatei, Origin:= _
xlWindows, StartRow:=1, DataType:=xlDelimited, Semicolon:=True _
, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1))




Markus Mannheim wrote:

Hi,

the followin cde imports a txt file to excel:

Private Sub Workbook_Open()

Application.DisplayAlerts = False

'Meldung wird angezeigt

MsgBox "Bitte selektieren Sie die zu ladende Adressdaten-Datei!"
ChDir "\"
ChDrive "G:\"
ChDir "operating\handy\adressdaten"
ZuOeffnendeDatei = Application.GetOpenFilename("Textdateien
(*.txt),*.txt")
If ZuOeffnendeDatei = False Then
Exit Sub
End If
Application.ScreenUpdating = False

Workbooks.OpenText Filename:=ZuOeffnendeDatei, Origin:= _
xlWindows, StartRow:=1, DataType:=xlDelimited, Semicolon:=True _
, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1))

'Herkunftsdatei wird Variable zugewiesen

ZuOeffnendeDatei = ActiveWorkbook.Name

Workbooks(ZuOeffnendeDatei).Activate
Selection.CurrentRegion.Select
Selection.Copy
Workbooks(ZuOeffnendeDatei).Close
Windows("export_outlook.xls").Activate
Sheets("Tabelle1").Select
Range("A1").Select
Selection.PasteSpecial
Selection.Columns.AutoFit
Range("A1").Select

Unfortunately the data in column 4 and 5 are telephone numbers, which
will
be incorrectly imported:
a number = 005541995799999 will be shown as 5.542E+11
I tried to set format the columns with number format = "@" in advance,
but
it didn't help.

For help thanks in advance,

Regards,
Markus


--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I import text file of cash flow to excel file then use formula Bumpa Excel Discussion (Misc queries) 2 May 28th 10 04:22 PM
open *.csv file as *.xls makro kajro Excel Programming 1 November 13th 05 07:31 PM
How do I import text file, analyze data, export results, open next file Geoffro Excel Programming 2 March 6th 05 08:02 PM
Import Makro Philipp Oberleitner Excel Programming 0 July 6th 04 09:53 AM
Import text file into excel with preset file layout, delimeters VBA meldrape Excel Programming 7 June 15th 04 08:31 PM


All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"