Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatic document saving in VBA upon closing

Status
Not open for further replies.

DaffyDukk

Programmer
Mar 13, 2001
3
GB
I am trying to eliminate user interaction when naming documents that need to be saved. Basically, I need to know the coding that will enable me to be able to save a document automatically, giving it the file name of 'time and date', and specifying where the file will be saved as well. I am almost there I think, I can get the document to bring up the Save As dialogue box, but I can't quite get to the next stage, and I am unsure if I am going about this in the right way! Thanks in advance for your help.
 
For saving a Word document:

Sub test()
Dim oDoc As Document
Dim sFile As String
Dim sLoc As String

sLoc = "C:\TEMP\"

sFile = sLoc & Format$(Now, "YYYYMMDDHHNNSS") & ".doc"

Set oDoc = ActiveDocument
oDoc.SaveAs FileName:=sFile
oDoc.Close
Set oDoc = Nothing
End Sub

For an Excel workbook, change
Dim oDoc As Document
to
Dim oDoc As Workbook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top