Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default change folder

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?







  #2   Report Post  
Posted to microsoft.public.excel.programming
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?









  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default change folder

John,

Disregard the previous information that I gave. It looks like you used the
MacroRecorder to record importing a file using the "Data | Import External
Data | Import Data..." command from the menubar.

You will need to modify the following line of code in
"ImportChurchSchedule":

From: "TEXT;C:\EMP3\Tab files for Excel\EM Church Schedule.tab",

To: "TEXT;C:\EMP4\Tab files for Excel\EM Church Schedule.tab",

Or you could repeat using the MacroRecorder to record importing the file
from it's new location

Troy

"John Garate" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default change folder

Troy,
I'ts when I change the line of code to "TEXT;C:\EMP4\Tab files for Excel\EM
Church Schedule.tab",
that the macro hangs. The only thing Ive done is change EMP3 to EMP4.
I know I could repeat using the MacroRecorder, but this is a diddicult
process because of the query. I was hoping to just to edit the code.

John



"TroyW" wrote in message
...
John,

Disregard the previous information that I gave. It looks like you used the
MacroRecorder to record importing a file using the "Data | Import External
Data | Import Data..." command from the menubar.

You will need to modify the following line of code in
"ImportChurchSchedule":

From: "TEXT;C:\EMP3\Tab files for Excel\EM Church Schedule.tab",

To: "TEXT;C:\EMP4\Tab files for Excel\EM Church Schedule.tab",

Or you could repeat using the MacroRecorder to record importing the file
from it's new location

Troy

"John Garate" wrote in message
...
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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default change folder

John,

I've tested changing: "TEXT;C:\EMP4\" and it works for me. What is the exact
error message that you are receiving?

Troy

"John Garate" wrote in message
...
Troy,
I'ts when I change the line of code to "TEXT;C:\EMP4\Tab files for
Excel\EM Church Schedule.tab",
that the macro hangs. The only thing Ive done is change EMP3 to EMP4.
I know I could repeat using the MacroRecorder, but this is a diddicult
process because of the query. I was hoping to just to edit the code.

John





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default change folder

TroyW,
I finally got it working. The problem was that the macro is in a template
and I was changing the macro in a worksheet created by the template. I
should have been changing the macro in the template. I thought the changes
you make to a macro in a worksheet updates the macro in the template.

Thanks for all your help


John
"TroyW" wrote in message
...
John,

I've tested changing: "TEXT;C:\EMP4\" and it works for me. What is the
exact error message that you are receiving?

Troy

"John Garate" wrote in message
...
Troy,
I'ts when I change the line of code to "TEXT;C:\EMP4\Tab files for
Excel\EM Church Schedule.tab",
that the macro hangs. The only thing Ive done is change EMP3 to EMP4.
I know I could repeat using the MacroRecorder, but this is a diddicult
process because of the query. I was hoping to just to edit the code.

John





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
How to change a reference when the sheet change the folder? WonderOlga Excel Worksheet Functions 2 January 3rd 08 09:19 PM
... I'd like to change the Default Folder... Dr. Darrell Excel Discussion (Misc queries) 4 September 11th 07 04:12 PM
how can i change my default working folder to a networked folder? wizard1154 Excel Discussion (Misc queries) 4 April 18th 07 07:29 PM
Change Default Add-in Folder compound Excel Discussion (Misc queries) 2 July 13th 05 10:25 PM
Change Folder Icon James Stephens[_2_] Excel Programming 1 May 9th 04 08:42 PM


All times are GMT +1. The time now is 11:09 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"