![]() |
|
|
| Subject:
MS Word Macro
Category: Computers > Programming Asked by: rs2010-ga List Price: $10.00 |
Posted:
25 Aug 2006 12:59 PDT
Expires: 28 Aug 2006 17:33 PDT Question ID: 759537 |
I am in need of a MS Word (XP or later) macro. Assume the user is editing a file that is from a document template that is read only. The user will then click on a button on the toolbar that does the following: If current filename is ?letter_template? then Save the file as C:\DocumentFolder\ + ?MyLetter? + CurrentDate + CurrentTime Else Save (which keeps the current file name and path) End If Purpose: We have a freind who has special needs. He is not able to recall or determine if he has already saved the file that he is creating or not. In other words, he first opens the new template (from a shortcut on the desktop) and types in his text. At this time, he is supposed to select "Save As", give the file a meaningful name, and then save it to the appropriate location. Every time thereafter, he is supposed to select "Save". He cannot remember these rules. I want a macro that will do this for him. Your help is appreciated. | |
|
|
| There is no answer at this time. |
|
| Subject:
Re: MS Word Macro
From: wardd-ga on 25 Aug 2006 15:29 PDT |
a solution to part of your problem... make the template read only. And for that matter you can even make the folder/drive read only to that user forcing them to name the document something else in another location. I feel your pain on this problem. |
| Subject:
Re: MS Word Macro
From: rhinst-ga on 26 Aug 2006 21:32 PDT |
First of all, make sure you are able to run macros by clicking
Tools->Options, then click the Security tab and click Macro Security.
Make sure Security Level is set to Medium or lower.
Then click Tools->Macro->Visual Basic Editor (or just press Alt+F11)
to bring up the code editor window. There should be a project window
in the top left. In it, under Project (letter_template), there should
be an icon that says ThisDocument. double click it and past the
following into the code window:
Function padString(ByVal origStr As String, ByVal padSize As Integer,
ByVal padStr As String)
Dim newStr As String
For i = 1 To padSize
newStr = newStr & padStr
Next i
newStr = newStr & origStr
newStr = Right(newStr, padSize)
padString = newStr
End Function
Sub FileSave()
Dim dateStr As String
If (ThisDocument.Name = "letter_template.doc") Then
dateStr = padString(Month(Now), 2, "0") & "_"
dateStr = dateStr & padString(Day(Now), 2, "0") & "_"
dateStr = dateStr & Year(Now) & " "
dateStr = dateStr & padString(Hour(Now), 2, "0") & "_"
dateStr = dateStr & padString(Minute(Now), 2, "0") & "_"
dateStr = dateStr & padString(Second(Now), 2, "0")
ThisDocument.SaveAs "c:\DocumentsFolder\MyLetter" & dateStr & ".doc"
End If
ActiveDocument.Save
End Sub
Save the file and that's all you need to do. Next time you open the
file and edit it and click save, it will automatically do what you
want. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |