Results 1 to 14 of 14
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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 <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    diana

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

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

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

    <code>ActiveDocument.Saved = True
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    </code>
    StuartR

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VBA code no longer works :o) (Word 2002 /XP SP

    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)?

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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 <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  5. #5
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Hi Diana,

    In a reply to your <post:=592,399>post 592,399</post:> 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...

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VBA code no longer works :o) (Word 2002 /XP SP

    <P ID="edit" class=small>(Edited by jscher2000 on 15-Oct-06 22:47. Corrected severe typo)</P>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:

    <code>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</code>

  7. #7
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

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

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  9. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    yeah tell me about it. its got me stumped.

    ill apply Jeffersons suggestions...cross fingers [img]/forums/images/smilies/ohmy.gif[/img])

    diana

  10. #10
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA code no longer works :o) (Word 2002 /XP SP

    do you have a before close event running?

  11. #11
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA code no longer works :o) (Word 2002 /XP SP

    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

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA code no longer works :o) (Word 2002 /XP SP

    You can either call Add as a procedure

    Documents.Add , , , False

    or as a function

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

  13. #13
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA code no longer works :o) (Word 2002 /XP SP

    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

  14. #14
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA code no longer works :o) (Word 2002 /XP SP

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •