Consulting

Results 1 to 4 of 4

Thread: save and close without asking

  1. #1

    save and close without asking

    I have this code in excel. What it does is it minimizes the excel window takes a print screen of whatever is behind it then brings up word pastes it in word then brings the excel window to normal.

    But, I need/want it to save the word doc as the string (saveit) and then close without asking anything.

    any help

    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
      bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Private Const VK_SNAPSHOT = &H2C
    
    
    
    Sub PrintScreen2Word()
    Application.ScreenUpdating = False
    
    Dim saveit As String
    
    saveit = "thisisatest"
    
        'Minimize Excel
        Application.WindowState = xlMinimized
        'Wait 2 seconds to allow time for the minimization
        Sleep (2000)
        'Take Screen Shot
        keybd_event VK_SNAPSHOT, 0, 0, 0
        'Open a new Word document
        Set wrdApp = CreateObject("Word.Application")
        wrdApp.Visible = True
        Set wrdDoc = wrdApp.Documents.Add
        'Paste
        wrdApp.Selection.Paste
        'some error checkin
        Set wrdDoc = Nothing
        Set wrdApp = Nothing
      
    Application.WindowState = xlNormal
      
      
        
    Application.ScreenUpdating = True
    
        End Sub
    [IMG]file:///C:/DOCUME%7E1/COMPUT%7E1/LOCALS%7E1/Temp/moz-screenshot.jpg[/IMG]

  2. #2
     WrdDoc.SaveAs _
    Filename:="C:\Documents and Settings\Computer 1\My Documents\pleasework.doc"
       wrdApp.Quit
    i did that.. anyone got anything better this seems to work

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    As a matter of cleanliness, I would actually specifically close the Word doc, but it can also be argued that it will be cleaned up without doing so. Code to do that would be as follows. (I *think* that the savechanges:=false will work for Word as it does for Excel).

    [vba]WrdDoc.SaveAs _
    Filename:="C:\Documents and Settings\Computer 1\My Documents\pleasework.doc"
    wrdDoc.Close savechanges:=false
    wrdApp.Quit[/vba]

    One question I have though... why are you setting the Word application visible? If you're just pasting a picture in and saving the file, do you really need Word to flash by? I'd be very surprised if it didn't work just fine without doing so.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4
    Quote Originally Posted by Ken Puls
    As a matter of cleanliness, I would actually specifically close the Word doc, but it can also be argued that it will be cleaned up without doing so. Code to do that would be as follows. (I *think* that the savechanges:=false will work for Word as it does for Excel).

    [vba]WrdDoc.SaveAs _
    Filename:="C:\Documents and Settings\Computer 1\My Documents\pleasework.doc"
    wrdDoc.Close savechanges:=false
    wrdApp.Quit[/vba]
    One question I have though... why are you setting the Word application visible? If you're just pasting a picture in and saving the file, do you really need Word to flash by? I'd be very surprised if it didn't work just fine without doing so.
    you're right, I didn't even realize that. It's runs much cleaner now that i set it to false.

    thanks for picking that up

Posting Permissions

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