PDA

View Full Version : Prepopulation of Save As field.



IcePirate
05-04-2009, 12:40 PM
Quick question, my code is below...

But is there a VBA code I can add into my Word Macro here, or even another Macro all together, so that when users click > File > Save As the 'Save As' field prepopulates that field with today's date in this format:

YYYY-MM-DD


Not sure if my current VBA code will help with this problem, but here it is:



Sub AutoOpen()
Dim myWB As Excel.Workbook
Dim TempStr As String
Dim intRows As Integer
Dim intRecords As Integer
Dim intProjects As Integer
Dim intCount As Integer
Dim strEmployee(0 To 1000) As String
Set myWB = GetObject("X:\2009 Core Projects.xls")
Selection.GoTo What:=wdGoToBookmark, Name:="first_mark"
TempStr = "Start"
intRows = 3
'Get all projects
Do While TempStr <> ""
intRows = intRows + 1
TempStr = myWB.Sheets("Sheet1").Cells(intRows, 3)
Loop
intRows = intRows - 1
intProjects = intRows
'Get all employees
For intRecords = 3 To intRows
If (myWB.Sheets("Sheet1").Cells(intRecords, 9) = "Not Started" Or myWB.Sheets("Sheet1").Cells(intRecords, 3) = "") Then
Else
strEmployee(intRecords) = myWB.Sheets("Sheet1").Cells(intRecords, 5)
End If
Next
'List employees and projects in Word Document
For intRecords = 3 To intRows
If strEmployee(intRecords) <> "" Then
'Has this employee already been entered into the Word Report?
For intCount = 3 To intRecords - 1
'Already in Word Report - Move to next employee
If strEmployee(intRecords) = strEmployee(intCount) Then GoTo Reported
Next
'Not In Word Report - Include in Document
Selection.TypeText strEmployee(intRecords)

'Bold Names
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.EndKey Unit:=wdLine
Selection.TypeText vbCr
Selection.Font.Bold = wdToggle

For intCols = 1 To intProjects
If myWB.Sheets("Sheet1").Cells(intCols, 5) = strEmployee(intRecords) Then
If myWB.Sheets("Sheet1").Cells(intCols, 9) <> "Not Started" Then
Selection.TypeText myWB.Sheets("Sheet1").Cells(intCols, 3) & vbCr
End If
End If
Next
'Spacer to next employee
Selection.TypeText vbCr
Reported:
End If
Next
Set myWB = Nothing
End Sub

IcePirate
05-04-2009, 01:01 PM
I may have figured it out, but still open to suggestions

...Add a command button, then in the code of the command button, put: (but Im still trying to make this work without having to use a command button)

Sub Test()
Dim Today, FolderName$, DateValue$, NameofFile$, FullFileName$
FolderName$ = "D:\"
DateValue$ = Format(Now, "yy-mm-dd")
NameofFile$ = "fred"
FullFileName$ = FolderName$ + DateValue$ + " " + NameofFile$
ActiveDocument.SaveAs FileName:=FullFileName$, FileFormat:=wdFormatDocument
End Sub

lucas
05-06-2009, 01:28 PM
I would put it in the thisworkbook module in the document close procedure.

Option Explicit
Private Sub Document_Close()
Dim Today, FolderName$, DateValue$, NameofFile$, FullFileName$
FolderName$ = "D:\"
DateValue$ = Format(Now, "yy-mm-dd")
NameofFile$ = "fred"
FullFileName$ = FolderName$ + DateValue$ + " " + NameofFile$
ActiveDocument.SaveAs FileName:=FullFileName$, FileFormat:=wdFormatDocument
End Sub
Be sure to put it in the thisdocument module or it won't work. If I were you I would put my autoIpen code into the thisworkbook module also in the document open event.