Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Microsoft Office и VBA программирование > Microsoft Office Excel
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 28.07.2009, 20:44   #11
london735
Пользователь
 
Регистрация: 20.06.2008
Сообщений: 45
По умолчанию

OK...I figured it out, the second parameter in Array(Array(1, 2) should be changed to 1
I have one more question:
How do I prevent the import of the text files which have already been analyzed? The text file names are recoded in the columns C of the A+B workbook.
I need this small modification to the macro given above. I guess the code should check if the name of the text file to be imported is already present in this column...I ask for your help in adding this modification because the workbook cycles through all the available text files whenever I start the macro - even if there in only ONE new file in the folder that needs to be analyzed.
london735 вне форума Ответить с цитированием
Старый 29.07.2009, 06:12   #12
SAS888
Старожил
 
Аватар для SAS888
 
Регистрация: 05.12.2007
Сообщений: 4,180
По умолчанию

We have subline of the code FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2),Array(6, 2)).
In each Array(x, y) - x is number imported column, y - is option.
There is explanation in reference (Help for VBA Excel):
Цитата:
XlColumnDataType can be one of these XlColumnDataType constants.
xlGeneralFormat General
xlTextFormat Text
xlMDYFormat MDY date
xlDMYFormat DMY date
xlYMDFormat YMD date
xlMYDFormat MYD date
xlDYMFormat DYM date
xlYDMFormat YDM date
xlEMDFormat EMD date
xlSkipColumn Skip Column
For example, Array(1, 2) - format of column 1 is "Text", Array(5, 1) - format of column 5 is "General", Array(6, 9) - column 6 will be absent.

That macro processed all files in folder (without the ".txt" suffix), line of the macro's code
Код:
FName = Dir(FPath & "*.txt")
change on
Код:
FName = Dir(FPath & "*")
To prevent the import of the text files, which are already analysed, possible so:
Код:
Sub AllFilesProcessing()
    Dim FPath As String, FName As String, x As Range: Application.ScreenUpdating = False: Application.DisplayAlerts = False
    FPath = "C:\MyTemp\" 'Insert path
    FName = Dir(FPath & "*")
    Do While FName <> ""
        Set x = Sheets("A+B").Columns("C").Find(what:=FName, LookAt:=xlWhole)
        If x Is Nothing Then
            Range([A50], Cells(Rows.Count, "F")).ClearContents
            Workbooks.OpenText Filename:=FPath & FName, Origin:=xlWindows, DataType:=xlDelimited, _
                Space:=True, FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 1))
            With ThisWorkbook.Sheets("1")
                Range([A1], Cells(Rows.Count, "F").End(xlUp)).Copy: .[A50].PasteSpecial Paste:=xlPasteValues: .[B48] = FName
            End With
            ActiveWorkbook.Close
            GATHERCORRECTED
        End If
        FName = Dir
    Loop
    [C1].Select: MsgBox "Done"
End Sub
Чем шире угол зрения, тем он тупее.

Последний раз редактировалось SAS888; 29.07.2009 в 07:10.
SAS888 вне форума Ответить с цитированием
Старый 29.07.2009, 19:51   #13
london735
Пользователь
 
Регистрация: 20.06.2008
Сообщений: 45
По умолчанию

thank you!!! I used the correction that you provided to record the file without the TXT suffix but it continues to record them this way. How can this be corrected?
Hoping to hear form you soon!))
london735 вне форума Ответить с цитированием
Старый 29.07.2009, 19:54   #14
london735
Пользователь
 
Регистрация: 20.06.2008
Сообщений: 45
По умолчанию

BTW that part of the macro which checks if the text files has already been analyzed - works perfectly!)
THANK YOU VERY MUCH FOR IT!)
london735 вне форума Ответить с цитированием
Старый 30.07.2009, 04:48   #15
SAS888
Старожил
 
Аватар для SAS888
 
Регистрация: 05.12.2007
Сообщений: 4,180
По умолчанию

Do you want to write the name of the processed files without the TXT suffix in cell of worksheet? This possible, but then compare the current filename with names, which is processed already, will not comfortable. Or do you want something another? Where are names without the TXT suffix must be written?
Чем шире угол зрения, тем он тупее.
SAS888 вне форума Ответить с цитированием
Старый 30.07.2009, 17:11   #16
london735
Пользователь
 
Регистрация: 20.06.2008
Сообщений: 45
По умолчанию

thanks you - I just need ot record text file names without the ".TXT" suffix - I will rename the records of the files which have already been analyzed. There needs to be no change for the location of the files - only the names of the recorded files should change to be pure - without TXT.
Thank you for your continuing help and I hope to hear form you soon!
london735 вне форума Ответить с цитированием
Старый 31.07.2009, 06:09   #17
SAS888
Старожил
 
Аватар для SAS888
 
Регистрация: 05.12.2007
Сообщений: 4,180
По умолчанию

If I have understood You it is correct, that You need for following:
You should change code
Код:
.[B48] = FName
on code
Код:
.[B48] = Left(FName, Len(FName) - 4)
If extension can contain free amount a symbols, that you may use method "GetBaseName" from FileSystemObject.
Чем шире угол зрения, тем он тупее.
SAS888 вне форума Ответить с цитированием
Старый 01.08.2009, 00:23   #18
london735
Пользователь
 
Регистрация: 20.06.2008
Сообщений: 45
По умолчанию

Цитата:
Сообщение от SAS888 Посмотреть сообщение
If I have understood You it is correct, that You need for following:
You should change code
Код:
.[B48] = FName
on code
Код:
.[B48] = Left(FName, Len(FName) - 4)
If extension can contain free amount a symbols, that you may use method "GetBaseName" from FileSystemObject.
Thank you very much!))))) Got home very late this evening - going to test it tomorrow and let you knwo how it goes....Have a great weekend!)
london735 вне форума Ответить с цитированием
Старый 02.08.2009, 00:01   #19
london735
Пользователь
 
Регистрация: 20.06.2008
Сообщений: 45
По умолчанию

thanks! I checked and it work but that part of the macro that looks for the file names does not appear to be working now (as it is searching for the full text name while it should look for the clean filename, without TXT suffix)....do I change this line:

Find(what:=FName, LookAt:=xlWhole)

to

Find(what:=Left(FName, Len(FName) - 4), LookAt:=xlWhole)

Thanks again!
london735 вне форума Ответить с цитированием
Старый 03.08.2009, 04:50   #20
SAS888
Старожил
 
Аватар для SAS888
 
Регистрация: 05.12.2007
Сообщений: 4,180
По умолчанию

Just so. If we write the name of the files without TXT suffix, signifies and search for it is necessary also.
Чем шире угол зрения, тем он тупее.
SAS888 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Data Validation HTR Microsoft Office Excel 2 28.03.2009 18:17
ощибка в import Yurka Общие вопросы по Java, Java SE, Kotlin 1 11.12.2008 14:20
Data Explorer gotex БД в Delphi 12 05.05.2008 22:04
Data neas Помощь студентам 1 03.03.2008 16:26
import из excel Toxa Общие вопросы Delphi 2 25.03.2007 19:53