Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saving to "MyDocuments" on users computer

I am writing a macro i want to be able to save a file to the users "My
Document/expired contracts". Not all users have the same path to My
Documents. Does VBA recognize %user% type commands? What would be the proper
syntax to make this work.
Thanks
Duane Reynolds


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Saving to "MyDocuments" on users computer

You can find the "my documents" path with something like:

Option Explicit
Sub testme()
Dim myDocumentsPath As String

Dim wsh As Object

Set wsh = CreateObject("WScript.Shell")
myDocumentsPath = wsh.SpecialFolders.Item("mydocuments")

MsgBox myDocumentsPath

End Sub


Duane Reynolds 323310 wrote:

I am writing a macro i want to be able to save a file to the users "My
Document/expired contracts". Not all users have the same path to My
Documents. Does VBA recognize %user% type commands? What would be the proper
syntax to make this work.
Thanks
Duane Reynolds


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Saving to "MyDocuments" on users computer

Dave,
I gave this a try and obviously do not have the WScript set up as a
reference under the Tools, Ref Dialog -- What is the official name
in this program in this listing so that I can add it?

If I add this ref, will it add unnecessary overhead to my systems memory
everytime I load Excel - as I likely will not go further with the use of
the WScript program except for this example..?

Thanks,
jim

" wrote in message
:

You can find the "my documents" path with something like:

Option Explicit
Sub testme()
Dim myDocumentsPath As String

Dim wsh As Object

Set wsh = CreateObject("WScript.Shell")
myDocumentsPath = wsh.SpecialFolders.Item("mydocuments")

MsgBox myDocumentsPath

End Sub


Duane Reynolds 323310 wrote:

I am writing a macro i want to be able to save a file to the users "My
Document/expired contracts". Not all users have the same path to My
Documents. Does VBA recognize %user% type commands? What would be the proper
syntax to make this work.
Thanks
Duane Reynolds


--

Dave Peterson


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Saving to "MyDocuments" on users computer

Since the code uses late binding (declaring wsh as an object), then you don't
need a reference in your workbook's project.

Using early binding (declaring your objects as the correct type), makes
development easier--you get the intellisense that pops up to help.

But using late binding is probably better for deployment to others. You don't
have to worry about a reference to a different version causing trouble for users
(and you!).

Option Explicit
Sub testme()

Dim myDocumentsPath As String

'with a reference to Windows Script Host Object Model
Dim wsh As IWshRuntimeLibrary.WshShell
Set wsh = New IWshRuntimeLibrary.WshShell

'late binding/no reference
'Dim wsh As Object
'Set wsh = CreateObject("WScript.Shell")

myDocumentsPath = wsh.SpecialFolders.Item("mydocuments")

MsgBox myDocumentsPath

'maybe even add this when you're done getting your info:
set wsh = nothing

'rest of real code here

End Sub

As for overhead, there will be some--I don't know how much and how unnecessary.

If you search Google, you'll see API equivalent that probably have less overhead
(I'm way out of my element here!), but I wouldn't hesitate to this code.



JMay wrote:

Dave,
I gave this a try and obviously do not have the WScript set up as a
reference under the Tools, Ref Dialog -- What is the official name
in this program in this listing so that I can add it?

If I add this ref, will it add unnecessary overhead to my systems memory
everytime I load Excel - as I likely will not go further with the use of
the WScript program except for this example..?

Thanks,
jim

" wrote in message
:

You can find the "my documents" path with something like:

Option Explicit
Sub testme()
Dim myDocumentsPath As String

Dim wsh As Object

Set wsh = CreateObject("WScript.Shell")
myDocumentsPath = wsh.SpecialFolders.Item("mydocuments")

MsgBox myDocumentsPath

End Sub


Duane Reynolds 323310 wrote:

I am writing a macro i want to be able to save a file to the users "My
Document/expired contracts". Not all users have the same path to My
Documents. Does VBA recognize %user% type commands? What would be the proper
syntax to make this work.
Thanks
Duane Reynolds


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saving to "MyDocuments" on users computer

You can also reference standard Windows XP profile folders for each user
using the following syntax:

Function GetProfilePath()
GetProfilePath = "C:\Documents and Settings\" & Environ$("username")& "\my
documents\"
End Function

Eugene



Duane Reynolds 323310 wrote:
I am writing a macro i want to be able to save a file to the users "My
Document/expired contracts". Not all users have the same path to My
Documents. Does VBA recognize %user% type commands? What would be the proper
syntax to make this work.
Thanks
Duane Reynolds




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Saving to "MyDocuments" on users computer


"ekim" <u32520@uwe wrote in message news:6f408f66dbbca@uwe...
You can also reference standard Windows XP profile folders for each user
using the following syntax:

Function GetProfilePath()
GetProfilePath = "C:\Documents and Settings\" & Environ$("username")& "\my
documents\"
End Function

Eugene


Which is fine assuming a default install of windows with my documents in the
location you describe. I have many machines where 'My Documents' is stored
on a separate drive or partition and therefore not c:\

--
Chris Lewis


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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Hashing function CryptAcquireContext Lib "advapi32" not working in new computer. Stephen Rasey[_3_] Excel Programming 5 December 25th 06 04:05 AM
stop users from saving their file over "master" if same name ruddojo Excel Programming 6 May 1st 06 05:47 AM
"Hyperlinks can be harmfull to your computer and data...." how to shut this off marko Excel Discussion (Misc queries) 0 February 17th 06 12:27 PM
Stop users from accessing "Protection" option from "Tools" menu I Believe Excel Programming 2 December 19th 05 02:44 PM


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