Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / January 2005



Tip: Looking for answers? Try searching our database.

Get application's default file location (the "save as" location)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mabond - 31 Jan 2005 11:02 GMT
Hi

My application includes a user option intended to perform as follows

1. Ask user for a filename of their own creation
2. Opens Powerpoint and creates a new presentation with that filename

and

3. Attempts to save the file

It is this 3) which is causing me a little problem. If I use

dim usersfilename as string
usersfilename = inputbox("Please type a filename of your choice")
................
ActivePresentation.SaveAs(filename:=usersfilename)

The file is being saved in the C:\WINNT\System32 directory and not in the
default ditrectory set in PowerPoint!!

I cannot hard-code the path/directory to include it in the
ActivePresentation.SaveAs line because I have multiple users who potentially
all have different default file locations set in PowerPoint.

Solution : read the default file location from the Application when it opens
and assign that to a variable to be used as the path.

Problem : I cannot find a method of reading the content of "Tools",
"Options", "Save tab", "default file location" when the application is first
opened

Does anyone have code that will do this or know of a way of reading an
applications default file location.

Thanks and regards

Michael Bond

Karl E. Peterson - 31 Jan 2005 19:55 GMT
> I cannot hard-code the path/directory to include it in the
> ActivePresentation.SaveAs line because I have multiple users who
[quoted text clipped - 10 lines]
> Does anyone have code that will do this or know of a way of reading an
> applications default file location.

Unfortunately, PowerPoint doesn't expose this path in its object model, as Word and
Excel do.  Looks to me like you'll need to read it directly from the registry.  I
found it on this machine (Office 2000) at:

 HKCU\Software\Microsoft\Office\9.0\PowerPoint\RecentFolderList\Default

At the least, that "9.0" in there will change from version to version.

Have fun...   Karl
Signature

[Microsoft Basic: 1976-2001, RIP]

mabond - 31 Jan 2005 20:45 GMT
Karl

thanks for that. I was guessing that was the case cos I din't have any probs
doing it in Excel (which is where I learned my VB...via VBA)..... there is an
issue though

I've just tried it on my terminal and, guess what, the default has "no value
set" on mine!!. So if I can't get it right on mine what chance have I got
with other users.....there are other values in the registry though that might
give me what i'm looking for.

However, I've looked at other possible workrounds. Since my boss wants as
many apps as possible migrated to VB.NET (don't ask why? its a boss thing),
I've looked at the options there and found I can use a
"systeminformation.username" function to help build what would be the
expected default path (C:\documents and
settings\systeminformation.username\My documents\" and have put in an error
trap to save it to the root directory if that dirtectory does not exist. It's
not perfect but it works and that's always the important thing ..... so maybe
VB.NET has its uses after all (all I need to do now is translate the rest of
the 650 lines of code!!)

Thanks again for looking at this for me

Regards

Michael Bond

> > I cannot hard-code the path/directory to include it in the
> > ActivePresentation.SaveAs line because I have multiple users who
[quoted text clipped - 20 lines]
>
> Have fun...   Karl
Karl E. Peterson - 31 Jan 2005 21:00 GMT
> thanks for that. I was guessing that was the case cos I din't have
> any probs doing it in Excel (which is where I learned my VB...via
[quoted text clipped - 4 lines]
> chance have I got with other users.....there are other values in the
> registry though that might give me what i'm looking for.

I'm sorry, it wasn't "(Default)" but an actual string entry named "Default" at that
branch that was set.  I suppose it doesn't surprise me if it's empty, though, if
you've never set it.  PowerPoint would probably use the MyDocuments folder in that
case, no?

> However, I've looked at other possible workrounds. Since my boss
> wants as many apps as possible migrated to VB.NET (don't ask why? its
> a boss thing),

LOL!  That'd be funny enough, were they just VB, but given the Office aspect of it
that's just downright hilarious.  (Tell him I said so, if it helps. <g>)

> I've looked at the options there and found I can use a
> "systeminformation.username" function to help build what would be the
[quoted text clipped - 4 lines]
> important thing ..... so maybe VB.NET has its uses after all (all I
> need to do now is translate the rest of the 650 lines of code!!)

Oh, don't be silly. <g>  There are Win32 functions designed to get all those special
folders.  For example, from a CSysFolders class of mine:

  Public Property Get Path(ByVal CSIDL As CSIDL_VALUES, Optional Default As Boolean
= True, Optional ForceCreation As Boolean = False) As String
     Dim Buffer As String
     Dim pidl As Long
     Dim nRtn As Long

     ' Create buffer for return results.
     Buffer = Space$(MAX_PATH)

     ' Branch based on what tools we have...
     If m_Enhanced Then
        ' Tell system to create, if necessary
        If ForceCreation Then
           CSIDL = CSIDL Or CSIDL_FLAG_CREATE
        End If

        ' Grab requested system folder.
        nRtn = SHGetFolderPath(0&, CSIDL, 0&, Abs(Default), Buffer)
        Select Case nRtn
           Case S_OK
              ' Return requested system folder.
              Path = TrimNull(Buffer)
           Case S_FALSE
              ' Folder either doesn't exist or isn't supported.
              Debug.Print "The CSIDL in nFolder is valid, but the folder does not
exist."
           Case E_INVALIDARG
              ' OS doesn't support this folder. Unfortunately, this
              ' result isn't returned unless CSIDL_FLAG_CREATE is
              ' specified in SHGetFolderPath call.
              Debug.Print "The CSIDL in nFolder is not valid."
        End Select

     Else
        ' Use old-fashioned method to get system folder.
        nRtn = SHGetSpecialFolderLocation(0&, CSIDL, pidl)
        Select Case nRtn
           Case S_OK
              ' Retrieve actual path, given the pidl.
              If SHGetPathFromIDList(pidl, Buffer) Then
                 Path = TrimNull(Buffer)
              End If
              Call CoTaskMemFree(pidl)
           Case E_INVALIDARG
              ' OS doesn't support this folder.
              Debug.Print "The CSIDL in nFolder is not valid."
           Case Else
              ' Some sort of OLE-defined error code
              Debug.Print "OLE error: &h" & Hex$(nRtn)
        End Select
     End If
  End Property

Pass that CSIDL_PERSONAL (&H5), and you'll get the exact path the user has designated
for this.  You need to beware that it's not at all always under "\Documents and
Settings" either!  Mine is set to C:\Docs, for example.

Later...   Karl
Signature

[Microsoft Basic: 1976-2001, RIP]

>>> I cannot hard-code the path/directory to include it in the
>>> ActivePresentation.SaveAs line because I have multiple users who
[quoted text clipped - 24 lines]
>> --
>> [Microsoft Basic: 1976-2001, RIP]
mabond - 31 Jan 2005 22:23 GMT
Karl

thnaks for this ........ much appreciate your help

Michael Bond

> > thanks for that. I was guessing that was the case cos I din't have
> > any probs doing it in Excel (which is where I learned my VB...via
[quoted text clipped - 116 lines]
> >> --
> >> [Microsoft Basic: 1976-2001, RIP]
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.