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!

Trying to close a Word Doc through VB w/o saving

Status
Not open for further replies.

hrm03

Programmer
Apr 30, 2003
28
US
I am trying to close a Word Doc through VB without saving it and its just not working. Through VB I have modified this document and printed it out, but I would like it to revert back to the original after it is printed and not save the modifications. I have tried making the file read only, but I keep getting an error message with that. Any help would be appreciated.
 
Hi hrm03,

Just do ..

Code:
ActiveDocument.Close wdDoNotSaveChanges

Enjoy,
Tony
 
Sorry Tony, I wasn't sure where to put this question. I have tried that 'ActiveDocument.close' but everything is still saved to the document.
 
Here's the thing. Through VB I am opening a file which contains Placeholder-Bookmarks. Using VB I am inserting information into those spaces, then printing the document. Once its printed, I do not want those bookmarks to contain information, they should be blank, like they were when the application was first loaded. And I want that file to close, with NO changes having been made. I have tried the code which you provided, but for some reason, when I open up the file, the new information is in place of the bookmarks. I am at a loss as to why the 'ActiveDocument.Close = False' doesn't work. Please let me know if you have any other ideas. Thanks.
 
Hi hrm03,

I'm confused. Is this a Word document (processed with the Word Application) or some other sort of file processed some other way? Can you post any code.

Enjoy,
Tony
 
What this does is take an existing doc and add information into its "bookmarks" then prints the document. The user never sees the document until it is printed. The problem I am having is trying to NOT save the information that is entered into the bookmark area. Thanks for your help!


Sub CreateWordDoc()

Dim iNbrOfInvoices As Integer
Dim iCtr As Integer
Dim objWdDoc As Word.Document
Dim BMRange As Range


'Selects the form to be filled in
Set objWdDoc = GetObject("c:\Documents and Settings\HMORAN\My Documents\30DayLetter.doc")

'Creates and fills in the table which shows the list of invoices and their info

iNbrOfInvoices = frmCollection.lstInvoices.ListCount
iCtr = 1
objWdDoc.Bookmarks("TableStart").Range.Select
objWdDoc.Tables.Add Selection.Range, iNbrOfInvoices, 4

For iCtr = 1 To iNbrOfInvoices
Selection.Tables(1).Cell(iCtr, 1).Select
Selection = "5778974"
Selection.Tables(1).Cell(iCtr, 2).Select
Selection = "10/01/03"
Selection.Tables(1).Cell(iCtr, 3).Select
Selection = "546487"
Selection.Tables(1).Cell(iCtr, 4).Select
Selection = "$135482.12"
Next iCtr


'Fills in all variable fields with information provided by ROI/Users

Set BMRange = ActiveDocument.Bookmarks("Name").Range
BMRange.Text = "HEATHER RAE XXXX"
ActiveDocument.Bookmarks.Add "Name", BMRange

Set BMRange = ActiveDocument.Bookmarks("Date").Range
BMRange.Text = Date
ActiveDocument.Bookmarks.Add "Date", BMRange

Set BMRange = ActiveDocument.Bookmarks("PageNbr").Range
BMRange.Text = "4"
ActiveDocument.Bookmarks.Add "PageNbr", BMRange

Set BMRange = ActiveDocument.Bookmarks("TotalBal").Range
BMRange.Text = "45645.12"
ActiveDocument.Bookmarks.Add "TotalBal", BMRange

'Automatically prints the document without opening word

Application.ScreenUpdating = True
ActiveDocument.PrintOut False
ActiveDocument.Close False
 
Tony-
Thank you for your help with this. I went ahead and re-created the actual word doc that I was trying to update and now the code is working. I guess there was something wrong with the document not the code. Thanks again! [smile2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top