directory question??

J

Joy

in our macros, we open csv file stored in Temp directory, get data in it and
map the data to MS project file.
However, each time after this, when user "Save As" the file, the directory
is changed to "Temp". I guess this is because when we read csv file, we open
the file (FileOpen name:=GetTempDir & "\Export.csv",
FormatID:="MSProject.CSV", Merge:=2, map:="Export Short Map")

I know how to get activeproject's name and path. my question is can I set
directory, so after the operation, the directory will be changed back to the
directory the MS project file is in, not the Temp

thanks
 
J

John

Joy said:
in our macros, we open csv file stored in Temp directory, get data in it and
map the data to MS project file.
However, each time after this, when user "Save As" the file, the directory
is changed to "Temp". I guess this is because when we read csv file, we open
the file (FileOpen name:=GetTempDir & "\Export.csv",
FormatID:="MSProject.CSV", Merge:=2, map:="Export Short Map")

I know how to get activeproject's name and path. my question is can I set
directory, so after the operation, the directory will be changed back to the
directory the MS project file is in, not the Temp

thanks

Joy,
Try the ChDrive or ChDir statements. For full syntax on those statements
look in the VBA library, (not the Project library), of the Object
Browser.

John
Project MVP
 
J

Joy

thank you

Well, it seems not work with MS project

I tried that on excel, and that works...

FileSystem.ChDir "C:\Documents and Settings"
 
J

John

Joy said:
thank you

Well, it seems not work with MS project

I tried that on excel, and that works...

FileSystem.ChDir "C:\Documents and Settings"

Joy,
Yes it will work with Project. Both of the directory type statements I
suggested are not associated with any specific application, rather, they
are are part of the generic VBA command set. I use both statements in
one of my Project macros. The syntax is simply,
ChDrive "C:"
ChDir "C:\documents and settings\John\my documents\[desired folder name]

The first insures my local hard drive is the active drive and the second
selects a specific folder on that drive.

John
Project MVP
 
J

Joy

I use this to get temp directory;

Private Function GetTempDir() As String
Dim tempDir As String

tempDir = getProjectProperty("TemporaryDirectory")
If tempDir = "" Then
GetTempDir = Environ("TEMP")
Else
GetTempDir = tempDir
End If
End Function

and fileopen a csv file in the directory. after that, I do:

ChDrive "C:"
ChDir "C:\Documents and Settings\myname\Desktop"

then when I saveas, the directory is still temp directory...not desktop

thank you

John said:
Joy said:
thank you

Well, it seems not work with MS project

I tried that on excel, and that works...

FileSystem.ChDir "C:\Documents and Settings"

Joy,
Yes it will work with Project. Both of the directory type statements I
suggested are not associated with any specific application, rather, they
are are part of the generic VBA command set. I use both statements in
one of my Project macros. The syntax is simply,
ChDrive "C:"
ChDir "C:\documents and settings\John\my documents\[desired folder name]

The first insures my local hard drive is the active drive and the second
selects a specific folder on that drive.

John
Project MVP
 
J

John

Joy said:
I use this to get temp directory;

Private Function GetTempDir() As String
Dim tempDir As String

tempDir = getProjectProperty("TemporaryDirectory")
If tempDir = "" Then
GetTempDir = Environ("TEMP")
Else
GetTempDir = tempDir
End If
End Function

and fileopen a csv file in the directory. after that, I do:

ChDrive "C:"
ChDir "C:\Documents and Settings\myname\Desktop"

then when I saveas, the directory is still temp directory...not desktop

thank you
Joy,
I ran a quick little test and indeed if you do a manual SaveAs the file
will be saved back to the temp directory. However, if you use FileSaveAs
in your macro after changing the directory, the file will be save to the
directory you specified. I'd incorporate the SaveAs into your VBA code.
If you need to have the user specify the new file name, add an InputBox
to get that information from the user before the FileSaveAs Method.

John
Project MVP
John said:
Joy said:
thank you

Well, it seems not work with MS project

I tried that on excel, and that works...

FileSystem.ChDir "C:\Documents and Settings"

Joy,
Yes it will work with Project. Both of the directory type statements I
suggested are not associated with any specific application, rather, they
are are part of the generic VBA command set. I use both statements in
one of my Project macros. The syntax is simply,
ChDrive "C:"
ChDir "C:\documents and settings\John\my documents\[desired folder name]

The first insures my local hard drive is the active drive and the second
selects a specific folder on that drive.

John
Project MVP
:

in our macros, we open csv file stored in Temp directory, get data in
it
and
map the data to MS project file.
However, each time after this, when user "Save As" the file, the
directory
is changed to "Temp". I guess this is because when we read csv file,
we
open
the file (FileOpen name:=GetTempDir & "\Export.csv",
FormatID:="MSProject.CSV", Merge:=2, map:="Export Short Map")

I know how to get activeproject's name and path. my question is can I
set
directory, so after the operation, the directory will be changed back
to
the
directory the MS project file is in, not the Temp

thanks

Joy,
Try the ChDrive or ChDir statements. For full syntax on those
statements
look in the VBA library, (not the Project library), of the Object
Browser.

John
Project MVP
 
J

Joy

yes, that would be a good way.
but if user has linked projects, and a message will be popped up asking
whether save all, or save, or cancel, sth like that.

I am not sure whether user really likes that

anyway, I will think about these ways and find a best way.
John said:
Joy said:
I use this to get temp directory;

Private Function GetTempDir() As String
Dim tempDir As String

tempDir = getProjectProperty("TemporaryDirectory")
If tempDir = "" Then
GetTempDir = Environ("TEMP")
Else
GetTempDir = tempDir
End If
End Function

and fileopen a csv file in the directory. after that, I do:

ChDrive "C:"
ChDir "C:\Documents and Settings\myname\Desktop"

then when I saveas, the directory is still temp directory...not desktop

thank you
Joy,
I ran a quick little test and indeed if you do a manual SaveAs the file
will be saved back to the temp directory. However, if you use FileSaveAs
in your macro after changing the directory, the file will be save to the
directory you specified. I'd incorporate the SaveAs into your VBA code.
If you need to have the user specify the new file name, add an InputBox
to get that information from the user before the FileSaveAs Method.

John
Project MVP
John said:
thank you

Well, it seems not work with MS project

I tried that on excel, and that works...

FileSystem.ChDir "C:\Documents and Settings"

Joy,
Yes it will work with Project. Both of the directory type statements I
suggested are not associated with any specific application, rather, they
are are part of the generic VBA command set. I use both statements in
one of my Project macros. The syntax is simply,
ChDrive "C:"
ChDir "C:\documents and settings\John\my documents\[desired folder name]

The first insures my local hard drive is the active drive and the second
selects a specific folder on that drive.

John
Project MVP

:

in our macros, we open csv file stored in Temp directory, get data in
it
and
map the data to MS project file.
However, each time after this, when user "Save As" the file, the
directory
is changed to "Temp". I guess this is because when we read csv file,
we
open
the file (FileOpen name:=GetTempDir & "\Export.csv",
FormatID:="MSProject.CSV", Merge:=2, map:="Export Short Map")

I know how to get activeproject's name and path. my question is can I
set
directory, so after the operation, the directory will be changed back
to
the
directory the MS project file is in, not the Temp

thanks

Joy,
Try the ChDrive or ChDir statements. For full syntax on those
statements
look in the VBA library, (not the Project library), of the Object
Browser.

John
Project MVP
 
J

Joy

And Thank you, John

John said:
Joy said:
I use this to get temp directory;

Private Function GetTempDir() As String
Dim tempDir As String

tempDir = getProjectProperty("TemporaryDirectory")
If tempDir = "" Then
GetTempDir = Environ("TEMP")
Else
GetTempDir = tempDir
End If
End Function

and fileopen a csv file in the directory. after that, I do:

ChDrive "C:"
ChDir "C:\Documents and Settings\myname\Desktop"

then when I saveas, the directory is still temp directory...not desktop

thank you
Joy,
I ran a quick little test and indeed if you do a manual SaveAs the file
will be saved back to the temp directory. However, if you use FileSaveAs
in your macro after changing the directory, the file will be save to the
directory you specified. I'd incorporate the SaveAs into your VBA code.
If you need to have the user specify the new file name, add an InputBox
to get that information from the user before the FileSaveAs Method.

John
Project MVP
John said:
thank you

Well, it seems not work with MS project

I tried that on excel, and that works...

FileSystem.ChDir "C:\Documents and Settings"

Joy,
Yes it will work with Project. Both of the directory type statements I
suggested are not associated with any specific application, rather, they
are are part of the generic VBA command set. I use both statements in
one of my Project macros. The syntax is simply,
ChDrive "C:"
ChDir "C:\documents and settings\John\my documents\[desired folder name]

The first insures my local hard drive is the active drive and the second
selects a specific folder on that drive.

John
Project MVP

:

in our macros, we open csv file stored in Temp directory, get data in
it
and
map the data to MS project file.
However, each time after this, when user "Save As" the file, the
directory
is changed to "Temp". I guess this is because when we read csv file,
we
open
the file (FileOpen name:=GetTempDir & "\Export.csv",
FormatID:="MSProject.CSV", Merge:=2, map:="Export Short Map")

I know how to get activeproject's name and path. my question is can I
set
directory, so after the operation, the directory will be changed back
to
the
directory the MS project file is in, not the Temp

thanks

Joy,
Try the ChDrive or ChDir statements. For full syntax on those
statements
look in the VBA library, (not the Project library), of the Object
Browser.

John
Project MVP
 
J

John

Joy said:
And Thank you, John

Joy,
You're welcome.
John
John said:
Joy said:
I use this to get temp directory;

Private Function GetTempDir() As String
Dim tempDir As String

tempDir = getProjectProperty("TemporaryDirectory")
If tempDir = "" Then
GetTempDir = Environ("TEMP")
Else
GetTempDir = tempDir
End If
End Function

and fileopen a csv file in the directory. after that, I do:

ChDrive "C:"
ChDir "C:\Documents and Settings\myname\Desktop"

then when I saveas, the directory is still temp directory...not desktop

thank you
Joy,
I ran a quick little test and indeed if you do a manual SaveAs the file
will be saved back to the temp directory. However, if you use FileSaveAs
in your macro after changing the directory, the file will be save to the
directory you specified. I'd incorporate the SaveAs into your VBA code.
If you need to have the user specify the new file name, add an InputBox
to get that information from the user before the FileSaveAs Method.

John
Project MVP
:

thank you

Well, it seems not work with MS project

I tried that on excel, and that works...

FileSystem.ChDir "C:\Documents and Settings"

Joy,
Yes it will work with Project. Both of the directory type statements I
suggested are not associated with any specific application, rather,
they
are are part of the generic VBA command set. I use both statements in
one of my Project macros. The syntax is simply,
ChDrive "C:"
ChDir "C:\documents and settings\John\my documents\[desired folder
name]

The first insures my local hard drive is the active drive and the
second
selects a specific folder on that drive.

John
Project MVP

:

in our macros, we open csv file stored in Temp directory, get
data in
it
and
map the data to MS project file.
However, each time after this, when user "Save As" the file, the
directory
is changed to "Temp". I guess this is because when we read csv
file,
we
open
the file (FileOpen name:=GetTempDir & "\Export.csv",
FormatID:="MSProject.CSV", Merge:=2, map:="Export Short Map")

I know how to get activeproject's name and path. my question is
can I
set
directory, so after the operation, the directory will be changed
back
to
the
directory the MS project file is in, not the Temp

thanks

Joy,
Try the ChDrive or ChDir statements. For full syntax on those
statements
look in the VBA library, (not the Project library), of the Object
Browser.

John
Project MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top