Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
bob bob is offline
external usenet poster
 
Posts: 6
Default Imported Text File Worksheet Tab Name

I created this macro using snippets of code I found in this news group.
The macro: (1) clears the worksheet (2) prompts the user to select
a textfile.txt to open (3) imports the textfile into sheet 1 and (4)
does a bit of formatting to the worksheet.

How can I make the tab reflect the name of the textfile that was opened
excluding the .txt ext?

Thanks

Here's the code below:

Cells.Select
Selection.ClearContents
Range("A1").Select

MyDataFile = Application.GetOpenFilename("Text Files,*.Txt")

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & MyDataFile, _
Destination:=Range("A1"))
.Name = "MyDataFile & Activesheet.QueryTable.counts +1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

End With
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Imported Text File Worksheet Tab Name

Dim shArr As Variant
Dim shName As String
myDatafile = "C:\Myfolder\MyfileName"
shArr = Split(myDatafile, "\")
shName = shArr(UBound(shArr))
If InStr(shName, ".") Then _
shName = Left(shName, InStr(shName, ".") - 1)
Activesheet.Name = shName

--
Regards,
Tom Ogilvy


"bob" wrote in message
...
I created this macro using snippets of code I found in this news group.
The macro: (1) clears the worksheet (2) prompts the user to select
a textfile.txt to open (3) imports the textfile into sheet 1 and (4)
does a bit of formatting to the worksheet.

How can I make the tab reflect the name of the textfile that was opened
excluding the .txt ext?

Thanks

Here's the code below:

Cells.Select
Selection.ClearContents
Range("A1").Select

MyDataFile = Application.GetOpenFilename("Text Files,*.Txt")

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & MyDataFile, _
Destination:=Range("A1"))
.Name = "MyDataFile & Activesheet.QueryTable.counts +1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

End With
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
bob bob is offline
external usenet poster
 
Posts: 6
Default Imported Text File Worksheet Tab Name

This gives me "MyFileName" on the tab,
what I need is for the name of the selected
file to appear on the tab. Also, the path is
not a constant; it is selected by the user.
Thanks
"Tom Ogilvy" wrote in message
...
Dim shArr As Variant
Dim shName As String
myDatafile = "C:\Myfolder\MyfileName"
shArr = Split(myDatafile, "\")
shName = shArr(UBound(shArr))
If InStr(shName, ".") Then _
shName = Left(shName, InStr(shName, ".") - 1)
Activesheet.Name = shName

--
Regards,
Tom Ogilvy


"bob" wrote in message
...
I created this macro using snippets of code I found in this news group.
The macro: (1) clears the worksheet (2) prompts the user to select
a textfile.txt to open (3) imports the textfile into sheet 1 and (4)
does a bit of formatting to the worksheet.

How can I make the tab reflect the name of the textfile that was opened
excluding the .txt ext?

Thanks

Here's the code below:

Cells.Select
Selection.ClearContents
Range("A1").Select

MyDataFile = Application.GetOpenFilename("Text Files,*.Txt")

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & MyDataFile, _
Destination:=Range("A1"))
.Name = "MyDataFile & Activesheet.QueryTable.counts +1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

End With
End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Imported Text File Worksheet Tab Name

your code gets the filename and path with

MyDataFile = Application.GetOpenFilename("Text Files,*.Txt")

The code I wrote and posted extracts the filename from the string in
MyDataFile

and names the sheet with that name. To test the code, I assigned a value to
myDatafile. I figured it was obvious that line should be removed, but
perhaps not.

Dim shArr As Variant
Dim shName As String
'myDatafile = "C:\Myfolder\MyfileName"
MyDataFile = Application.GetOpenFilename("Text Files,*.Txt")
shArr = Split(myDatafile, "\")
shName = shArr(UBound(shArr))
If InStr(shName, ".") Then _
shName = Left(shName, InStr(shName, ".") - 1)
Activesheet.Name = shName

or to put it all together.

Dim shArr As Variant
Dim shName As String

Cells.Select
Selection.ClearContents
Range("A1").Select

MyDataFile = Application.GetOpenFilename("Text Files,*.Txt")

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & MyDataFile, _
Destination:=Range("A1"))
.Name = "MyDataFile & Activesheet.QueryTable.counts +1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

End With
shArr = Split(myDatafile, "\")
shName = shArr(UBound(shArr))
If InStr(shName, ".") Then _
shName = Left(shName, InStr(shName, ".") - 1)
Activesheet.Name = shName
End Sub

--
Regards,
Tom Ogilvy




"bob" wrote in message
...
This gives me "MyFileName" on the tab,
what I need is for the name of the selected
file to appear on the tab. Also, the path is
not a constant; it is selected by the user.
Thanks
"Tom Ogilvy" wrote in message
...
Dim shArr As Variant
Dim shName As String
myDatafile = "C:\Myfolder\MyfileName"
shArr = Split(myDatafile, "\")
shName = shArr(UBound(shArr))
If InStr(shName, ".") Then _
shName = Left(shName, InStr(shName, ".") - 1)
Activesheet.Name = shName

--
Regards,
Tom Ogilvy


"bob" wrote in message
...
I created this macro using snippets of code I found in this news

group.
The macro: (1) clears the worksheet (2) prompts the user to select
a textfile.txt to open (3) imports the textfile into sheet 1 and (4)
does a bit of formatting to the worksheet.

How can I make the tab reflect the name of the textfile that was

opened
excluding the .txt ext?

Thanks

Here's the code below:

Cells.Select
Selection.ClearContents
Range("A1").Select

MyDataFile = Application.GetOpenFilename("Text Files,*.Txt")

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & MyDataFile,

_
Destination:=Range("A1"))
.Name = "MyDataFile & Activesheet.QueryTable.counts +1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

End With
End Sub








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
iTunes Library text file imported into Excel Craig J Excel Discussion (Misc queries) 4 September 13th 09 12:25 AM
formatting a text file imported into excel GinaH Excel Worksheet Functions 1 August 6th 09 08:30 PM
can I display the file name of the imported text file in another c John-G Excel Discussion (Misc queries) 0 May 13th 05 03:38 PM
if then elseif on text file imported into excel mike windbigler Excel Programming 1 July 26th 04 11:48 AM
Can worksheet data be exported/imported to/from flat file? Joseph Geretz Excel Programming 4 November 28th 03 09:12 AM


All times are GMT +1. The time now is 08:02 AM.

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"