Vba – close word with microsoft visual basic 6.5 macro

ms-wordvba

Platform : Microsoft Visual Basic 6.5 and MS words 2007

I am trying to do a macro to do some editing to an words enable file. Done research on how to close the Excel file without saving, which Santosh had successfully help me solve the problem Solution.Tried applying to words There is no error while compling and saving

Placed the following coding in TheDocument similar to where Santosh had teached me for excel.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Me.Close False

End Sub

tried to replaced Me.Close False with the following coding…

1) Me.close

2) Me.close(false)

3) ActiveDocument.Close

4) ActiveDocument.Close (false)

5) ActiveDocument.Quit

6) Application.Quit (False)

7) Application.Close

But doesn't work.


Because I would be using a vba script to run a script to Update my words documents and to print accordingly to my value input. After that the script will close this documents without saving(I don't it to prompt user that there is changes and prompt user to save). I want it to so call "force close" without any prompting.
For ms excel 2007… I access the Developer tools to go to MS Visual Basic 6.5
under the "ThisWorkbook"… i enter the following command..

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Me.Close False

End Sub

this command successfully close the excel without saving or any prompt (which is what i want)
tried to apply it to words2007

Private Sub Document_Close()
'Me.Close 'run-time error '4198'

'Me.Close (SaveChanges:=wdDoNotSaveChanges,OriginalFormat:=wdOriginalDocumentFormat,RouteDocument:=True)

'Me.Quit Savechanges:=wdDoNotSaveChanges

'Me.Close Savechanges:=wdDoNotSaveChanges

'Me.Close False 'run-time error '4198'

'ActiveDocument.Close False 'run-time error '4198'

'Document.Close False 'run time error '424' Object required

'Document.Close Savechanges:=wdDoNotSaveChanges  'run time error '424' Object required


'Document.Close Savechanges 'run time error '424' Object required


'Me.Close Savechanges 'run-time error '4198'  



'Documents.Close SaveChanges:=wdDoNotSaveChanges

End Sub

'Sub CloseAllDocuments()
' Documents.Close SaveChanges:=wdDoNotSaveChanges
'End Sub

all these commands i commented out all ended with errors

Best Answer

I finally found a solution after many tries and research

this is for reference for anyone who is trying to do the same things as mine.

key in this coding in "ThisDocument"


Private Sub Document_Close()

'This is to make the words think that the documents is saved.
'However in actually fact. Any changes would not be save upon closing of document
Me.Saved = True

End Sub

Related Topic