Solved

Word 2000 Macro

Posted on 2007-11-20
3
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

695 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