• VBA code no longer works :o) (Word 2002 /XP SP3)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » VBA code no longer works :o) (Word 2002 /XP SP3)

    Author
    Topic
    #435488

    A bit of background info for you, although I don’t know if this makes a difference. Switching our Word code to make it COMS compliant from ODMA .

    I’ve posted something similiar, that was for VB. but this is for VBA.

    In VBA, I have the following code that no longer works

    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

    and I’ve also tried

    ActiveDocument.Saved = False
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

    I’ve also used send keys, which didnt work.

    What happens is the Prompt dialog is displayed, and I dont want the end user to see this. (see below screen capture)

    any ideas?

    many thanks smile
    diana

    Viewing 1 reply thread
    Author
    Replies
    • #1029390

      Assuming that your post wasn’t a mistype, have you tried.

      ActiveDocument.Saved = True
      ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

      StuartR

      • #1029604

        Thanks for your replies.

        In VB I’ve used the following code below to get around the same issue…therefore it wasn’t a mistype.

        ActiveDocument.Saved = False
        ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

        However I just realised the line is a flag.

        ActiveDocument.Saved = False

        therefore the code you provided works.

        ActiveDocument.Saved = True
        ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

        Many thanks again
        diana smile

        • #1029637

          Hi Diana,

          In a reply to your post 592,399 regarding the same question in VB, I said the Boolean should be set to True, not False. So I’m a bit confused when you say it’s not a mistype…

          • #1033667

            Hello the same message is appearing iwith the following code

            this is the orginial code….on the line ‘close without saving’ the Word Save dialog is displayed to save the temp “document#”.
            For each document printed, a temp document is created and closed without saving changes. Meaning this increments the document number displayed in the dialog.

            Sub ClearPrintToFile()

            ‘ Create hidden new blank document

            Dim docTemp As Word.Document
            Set docTemp = Documents.Add(, , , False)
            With docTemp

            ‘ Print nonexistent page NOT to file

            .PrintOut Range:=wdPrintRangeOfPages, Pages:=”p999s99″, PrintToFile:=False

            ‘ Close without saving

            .Close wdDoNotSaveChanges
            End With

            ‘ Clean up objects

            If Not (docTemp Is Nothing) Then Set docTemp = Nothing
            End Sub

            so ive updated the save & close code to the following, however it still displays the the Word Save dialog to save the temp “document#”

            ‘ Tidy up. We are printing using the print option ‘Print to File’ turned on.
            ‘ This setting is left on until the next time you print. This is a Word limitation.
            ‘ Within Word each time the print dialog is called I’ve cleared this option. However
            ‘ if another system requires Word to print eg from DMS >Save for Email prints to the Jaws
            ‘ printer, or from CMS printing prebills, this print setting will be left on displaying
            ‘ the ‘Print to File’ dialog box prompting the user for a file name. The only way
            ‘ to clear this setting is to print & turn off this setting.
            ‘ We will be doing this by printing page 999 in section 99 does not exist!

            Sub ClearPrintToFile()

            ‘ Create hidden new blank document

            Dim docTemp As Word.Document
            Set docTemp = Documents.Add(, , , False)
            With docTemp

            ‘ Print nonexistent page NOT to file

            .PrintOut Range:=wdPrintRangeOfPages, Pages:=”p999s99″, PrintToFile:=False

            ‘ Close without saving
            ‘ dd DR-4887. the Save code had to be updated to COM for new DM upgrade
            .Saved = True
            .Close SaveChanges:=wdDoNotSaveChanges
            End With

            ‘ Clean up objects

            If Not (docTemp Is Nothing) Then Set docTemp = Nothing
            End Sub

            any ideas?
            many thanks diana

            • #1033671

              (Edited by jscher2000 on 15-Oct-06 22:47. Corrected severe typo)

              I don’t understand how Word can disobey the instruction to not save changes!!

              My only thought is that some other process is intervening at some point. If you press Ctrl+Break when the Save Changes dialog is displayed, and debug, do you end up in your code or somewhere else?

              Would you like to try the following? I thought it might provide a more effective alternative to Saved=True:

              Sub UndoAll(Optional doc As Word.Document)
              ' Undo all changes that can be undone to a specified document
              ' If no document is specified, use the ActiveDocument
              If (doc Is Nothing) Then Set doc = ActiveDocument
              While doc.Undo
              Wend
              End Sub

            • #1033672

              I’m as stunned by this as Jefferson and I think he may be right about another process interfering.

            • #1033883

              yeah tell me about it. its got me stumped.

              ill apply Jeffersons suggestions…cross fingers )

              diana

            • #1033905

              do you have a before close event running?

            • #1034040

              when i do a CTRL break it goes to the line in the code. there isnt any other

              Ive created the following code, and it seems to work for some reason.

              Documents.Add
              ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:=”p999s99″, PrintToFile:=False
              ActiveDocument.Saved = True
              ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

              I thought I might may the document invisible(hidden) so i have the folllowing line…however it debugs on this line. and wanting an =
              For this line to work do i need to set a variable to this line?
              ‘Documents.Add(, , , False)

              to….
              Set docTemp = Documents.Add(, , , False)

              diana

            • #1034051

              You can either call Add as a procedure

              Documents.Add , , , False

              or as a function

              Dim docTemp As Document
              docTemp = Documents.Add(, , , False)

            • #1034054

              I frequently use Documents add without ‘SETting’ it to a variable, so that should work.Maybe this ‘=’ issue has to do with the use of arguments. For clarity I always use Named Arguments instead of the syntax like you used: Documents.Add(, , , False). So I would use Documents.Add Visible:=False. HTH

            • #1034222

              I noticed that when i use the following syntax it closes the new document fine. and there are no left over document#
              Documents.Add

              However when I use the syntax
              Documents.Add(, , , False)

              the result is you can’t see the document# in the menu Window.(obviously as its invisible). However when you goto Exit and Quit Word, the prompt is displayed “Do you want to save document#”.

              For now I’ll use Documents.Add and observe the results and feedback from the users.

              many thanks again
              diana

    • #1029405

      If you press Ctrl+Break on that dialog, can you find any other code that might be running (e.g., an event procedure triggered by ActiveDocument.Close)?

    Viewing 1 reply thread
    Reply To: VBA code no longer works :o) (Word 2002 /XP SP3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: