Solved

Word 2000 Macro

Posted on 2007-11-20
3
251 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now