Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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,



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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,


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
opening files simultaneously with same name but different path Kim Excel Discussion (Misc queries) 2 September 26th 08 06:18 PM
Problem with references while opening Excel from IE using UNC path vrkorada Links and Linking in Excel 0 July 6th 07 02:53 PM
Opening a document without adding the path Tmf[_3_] Excel Programming 1 July 8th 05 05:26 AM
Opening a document without adding the path Tmf[_2_] Excel Programming 1 July 7th 05 04:25 PM
Opening file through UNC path changes my links mchambers_autocam Links and Linking in Excel 1 June 17th 05 08:35 AM


All times are GMT +1. The time now is 09:40 AM.

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

About Us

"It's about Microsoft Excel"