View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John Garate John Garate is offline
external usenet poster
 
Posts: 7
Default change folder

Troy,
I'm not sure what you are telling me. I really just starting to learn to use
visual basic. I don't see the querytables commands you refer to. I've pasted
a copy of the macro into this email.



Sub ImportChurchSchedule()
'
' ImportVisitSchedule Macro
' Macro recorded 2/11/2005 by Jag
'

'
Range("B3").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\EMP3\Tab files for Excel\EM Church Schedule.tab",
Destination:=Range( _
"B3"))
.Name = "EM Visit Schedule"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierNone
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.Refresh BackgroundQuery:=False
End With
End Sub
Sub FormateDateColumn()
'
' FormateDateColumn Macro
' Macro recorded 2/11/2005 by Jag
'

'
Columns("B:B").Select
Selection.NumberFormat = "mm-dd"
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = False
End With
Selection.NumberFormat = "mmm-dd"
Range("F14").Select
End Sub
Sub InsertData()
'
' InsertData Macro
' Macro recorded 2/11/2005 by Jag
'

'
Application.Run "ImportVisitSchedule"
Application.Run "SetColumnWidths"
Application.Run "FormateDateColumn"
End Sub

Public Sub Auto_Open()
Application.WindowState = xlMaximized
End Sub



"TroyW" wrote in message
...
John,

As a rule I don't view attachments. So I'm responding without having
viewed your macro. I'm guessing that you either have a PivotTable or
QueryTable in your Excel file.

The directory location of a source file is contained in two places
(Connnection & CommandText). In order to change the source location of the
text file you need to modify these two properties of the PT/QT.

1) PivotCaches(1).Connection = "the_new_connection_string"
2) PivotCaches(1).CommandText = "the_new_query_string"

-OR-

1) QueryTables(1).Connection = "the_new_connection_string"
2) QueryTables(1).CommandText = "the_new_query_string"

You will need to reference the PT/QT appropriately for your situation. Let
me know if you need help here.

Troy


"John Garate" wrote in message
...
Excel 2002, Win XP, SP-2

I created the attached macro to open a tab delimited file located in the
folder C:/EMP3. It works fine.

However, I've changed the folder name on the C drive to EMP4.

I've edited the macro to replace the reference EMP3 to EMP4, but it does
not
run. It seems to hang up at the Refresh BackgroundQuert: = False
statement
(at least what's the line the debugger lighlights).

What is the correct way to edit the macro when I change the file
location?