![]() |
Opening *.txt by code with varible path
Hello to all,
I´m triying to open a *.txt file in a variable path and with a variable name. C:\.....\year\weekXX\ After opening the select dialog box I select the *.txt file and convert with comma delimiters. -year- is the value of a cell in worksheet -weekXX- is the value of a cell in worksheet Thanks for your help |
Opening *.txt by code with varible path
Take a look at GetOpenFilename in VBA help.
-- HTH Bob Phillips "carloshernandezy" wrote in message ups.com... Hello to all, I´m triying to open a *.txt file in a variable path and with a variable name. C:\.....\year\weekXX\ After opening the select dialog box I select the *.txt file and convert with comma delimiters. -year- is the value of a cell in worksheet -weekXX- is the value of a cell in worksheet Thanks for your help |
Opening *.txt by code with varible path
Hello Bob,
I´ve been triying a code like this and it returns an error "13" in line Sub TXT_OPEN() Dim varDir, varYear, varWeek As String Dim ws As Workbook Dim RutaArchivo As String Set ws = ActiveWorkbook Application.DisplayAlerts = False varDir = "C:\....\VB\" varYear = Range("L8") varWeek = Range("L7") RutaArchivo = varYear & " \ " & varWeek ChDir " C:\....\VB\ varYear & " \ " & varWeek " archivoAAbrir = Application.GetOpenFilename("Archivos de texto (*.txt), *.txt") If archivoAAbrir < False Then ChDir " C:\....\VB\ " Workbooks.OpenText Filename:=archivoAAbrir, Origin:= _ xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _ xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _ Comma:=True, Space:=False, Other:=True, OtherChar:="|", FieldInfo:= _ Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7 _ , 1), Array(8, 1)) End If End Sub |
Opening *.txt by code with varible path
You can't use "C:\.....\
you have to put in the path explicitly. -- Regards, Tom Ogilvy "carloshernandezy" wrote in message ups.com... Hello Bob, I´ve been triying a code like this and it returns an error "13" in line Sub TXT_OPEN() Dim varDir, varYear, varWeek As String Dim ws As Workbook Dim RutaArchivo As String Set ws = ActiveWorkbook Application.DisplayAlerts = False varDir = "C:\....\VB\" varYear = Range("L8") varWeek = Range("L7") RutaArchivo = varYear & " \ " & varWeek ChDir " C:\....\VB\ varYear & " \ " & varWeek " archivoAAbrir = Application.GetOpenFilename("Archivos de texto (*.txt), *.txt") If archivoAAbrir < False Then ChDir " C:\....\VB\ " Workbooks.OpenText Filename:=archivoAAbrir, Origin:= _ xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _ xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _ Comma:=True, Space:=False, Other:=True, OtherChar:="|", FieldInfo:= _ Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7 _ , 1), Array(8, 1)) End If End Sub |
Opening *.txt by code with varible path
Tom I Know it´s only an example, it is complete in the original code.
Thanks for your advice. Regards, |
Opening *.txt by code with varible path
so this is your problem line?
ChDir " C:\....\VB\ varYear & " \ " & varWeek " Unless you just omitted and added double quotes arbitrarily as examples, then ChDir "C:\....\VB\" & varYear & " \ " & varWeek but since you did this RutaArchivo = varYear & " \ " & varWeek Why not just do ChDir "C:\....\VB\" & RutaArchivo -- Regards, Tom Ogilvy "carloshernandezy" wrote in message oups.com... Tom I Know it´s only an example, it is complete in the original code. Thanks for your advice. Regards, |
All times are GMT +1. The time now is 02:58 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com