PDA

View Full Version : save and close without asking



QuietRiot
07-06-2007, 05:51 PM
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
file:///C:/DOCUME%7E1/COMPUT%7E1/LOCALS%7E1/Temp/moz-screenshot.jpg

QuietRiot
07-06-2007, 06:30 PM
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

Ken Puls
07-07-2007, 02:04 PM
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).

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

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.

QuietRiot
07-07-2007, 02:19 PM
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).

WrdDoc.SaveAs _
Filename:="C:\Documents and Settings\Computer 1\My Documents\pleasework.doc"
wrdDoc.Close savechanges:=false
wrdApp.Quit
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