Solved

Word 2000 Macro

Posted on 2007-11-20
3
253 Views
Last Modified: 2010-04-24
Hi,
I wrote the following Macro in Word and added it as a button on the toolbar so that when any user connects to our Terminal Server and runs Word, they can save the current document to their local C:\.

ChangeFileOpenDirectory "\\tsclient\C\"
ActiveDocument.Save

This works fine, but it would be ideal to save the document to the users local My Documents folder. To do that requires a variable and I need help with that. I tried this but it doesn't work:

ChangeFileOpenDirectory "\\tsclient\C\Documents and settings\%UserProfile%\My Documents\"
ActiveDocument.Save

I think I'm on the right track, just need the correct variable for the current user, and proper syntax.

Thanks,
Bill
0
Comment
Question by:westone
3 Comments
 
LVL 8

Accepted Solution

by:
Galisteo8 earned 500 total points
ID: 20320415
Hi, Bill,

This might be what you're looking for:
http://word.mvps.org/faqs/MacrosVBA/GetCurUserName.htm

Once you've got the function in your code, you should be able to call it like this:

ChangeFileOpenDirectory "\\tsclient\C\Documents and settings\" & GetUserName & "\My Documents\"
ActiveDocument.Save


hth,
Galisteo8
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 20320433
You can use Environ

Sub SetFolderFromEnviron()
    Dim i As Integer
    Dim env() As String
   
    Do
        i = i + 1
        env = Split(Environ(i), "=")
        If UCase$(env(0)) = "USERNAME" Then
            ChangeFileOpenDirectory "\\tsclient\C\Documents and settings\" & env(1) & "\My Documents\"
            ActiveDocument.Save
            Exit Sub
        End If
    Loop Until UBound(env) < 1
   
    MsgBox "UserName not found"

End Sub
0
 

Author Closing Comment

by:westone
ID: 31410104
Thanks!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question