Joined
·
4,543 Posts
I have a form that i created in word 2007, it is protected. When it is filled out we print it and then don't save it so that the next time it is opened it is blank. Sometimes people forget to click "no" when the "do you want to save" box pops up and then I have to take the time to go back and clear out the form boxes. How do I prevent this?
I have tried:
ActiveDocument.Saved = True
ThisDocument.Saved = True
activeDocument.close savechanges:=false
The one in red will work with a test document, i.e. blank document, add the code, save, close. Open that document, type something and when you click close it won't ask if you want to save. BUT it won't work with my form.
Nothing seems to work. Any ideas?
Thanks.
The extra code just keeps track of a number, in an Excel file, for the number of times the form has been opened. I use this number as a document number on the form when its printed.
I have tried:
ActiveDocument.Saved = True
ThisDocument.Saved = True
activeDocument.close savechanges:=false
The one in red will work with a test document, i.e. blank document, add the code, save, close. Open that document, type something and when you click close it won't ask if you want to save. BUT it won't work with my form.
Nothing seems to work. Any ideas?
Thanks.
Code:
Private Sub Document_Close()
ActiveDocument.Saved = True
End Sub
Private Sub Document_Open()
Dim xdApp As Word.Application
Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlRange As Excel.Range
Dim sFile As String
Dim LastID As Integer
Dim NewID As Integer
'Set to the location of the Excel "database"
sFile = "\\DUI_NAS\data\Redirect\DUI School Info\DUIContractNumber.xlsx"
'Set all the variables for the necessary XL objects
Set xlApp = New Excel.Application
Set xlWorkbook = xlApp.Workbooks.Open(sFile)
'The used range assumes just one column in the first worksheet
Set xlRange = xlWorkbook.Worksheets(1).UsedRange
'Use a built-in Excel function to get the max ID from the used range
LastID = xlApp.WorksheetFunction.Max(xlRange)
'You may want to come up with some crazy algorithm for
'this, but I opted for the intense + 1
NewID = LastID + 1
'This will prevent the save dialog from prompting the user
xlApp.DisplayAlerts = False
'Add new value to textbox'
TextBox1 = NewID
TextBox11 = NewID
'Add the new value to the Excel "database"
xlRange.Cells(xlRange.Count + 1, 1).Value = NewID
'Save and close
Call xlWorkbook.Save
Call xlWorkbook.Close
'Clean Up
xlApp.DisplayAlerts = True
Call xlApp.Quit
Set xlWorkbook = Nothing
Set xlApp = Nothing
Set xlRange = Nothing
End Sub