LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default With ActiveSheet.QueryTables.Add

As I was going along, after writing the below, I realized
that you Dim'd the Variables in both Sub's, or I needed to
because I had two subs. in the end that was the
Solution. I needed to declare the Dim's in both Sub's.

Again Thank you.

I see that you made another change,

I moved the Dim's to the sImportData Sub and it worked
like a champ. Is it possible to pass or make available
the variable to both Sub's? As you saw I have two Sub's
or should I just have one?

I intended sAddSheet to get the strFileName variable(file
name from the designated directory), and then create the
sheet with that name. The sImportData would also use this
variable to pull data from the file into the new sheet.

Your help is greatly appreciated

Rob





-----Original Message-----
This worked for me, going to a network drive:
I am using xl2000, so I had to comment out two lines that

were specific to
your later version, but beyond that it worked.

Try going to the immediate window and test your path to

your file

? dir("\\TestDIR01\OUTPUT\Test.txt")

If you get an error, then your path isn't correct or the

file doesn't exist.





Declarations moved to the top.

Dim strSheetNewName As String
Dim strFileName As String


Sub sImportData()
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;\\LOGFS06\users\ogilvtw\" & strFileName _
, Destination:=Range("A1"))
.Name = strFileName
.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 = 70
.TextFileParseType = xlDelimited
.TextFileTextQualifier =

xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ":"
.TextFileColumnDataTypes = Array(1, 1)
' .TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub




Sub sAddSheet()
strSheetNewName = "Test"
strFileName = "Test.txt"
Sheets.Add
ActiveSheet.Name = strSheetNewName
MsgBox "New Sheet " & strSheetNewName & "

addded."
Call sImportData
End Sub

--
Regards,
Tom Ogilvy


"

wrote in message
...
I am trying to place a variable in the VBA Sub below.

It
does not seem to work. My objective is to go to a
directory to retrieve a text file and import it as a

Data
Query. The File name changes so I expect the need for a
variable in the place of the file name. This Sub is
called from another Sub. Both are included. The area

in
question is noted with the - on either side


Sub sImportData()
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;-----\\TestDIR01\OUTPUT\" & strFileName---

--
_
, Destination:=Range("A1"))
.Name = strFileName
.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 = 70
.TextFileParseType = xlDelimited
.TextFileTextQualifier =

xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ":"
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub


Dim strSheetNewName As String
Dim strFileName As String


Sub sAddSheet()
strSheetNewName = "Test"
strFileName = "Test.txt"
Sheets.Add
ActiveSheet.Name = strSheetNewName
MsgBox "New Sheet " & strSheetNewName & "
added."
Call sImportData
End Sub



.

 
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
QueryTables Interrupt if URL is Down Steve Hieb Excel Programming 0 November 17th 03 10:07 PM
ActiveSheet Graham[_3_] Excel Programming 0 July 30th 03 09:08 AM
ActiveSheet Ron de Bruin Excel Programming 0 July 29th 03 04:59 PM
ActiveSheet Graham[_3_] Excel Programming 0 July 29th 03 04:47 PM


All times are GMT +1. The time now is 04:58 PM.

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"