|
-
Jan 6th, 2003, 04:19 AM
#1
Thread Starter
Junior Member
Office Automation
Hi!
I am writing an application that will identify Save and Close all editable applications running on the PC like Word, Excel, PowerPoint etc. on the click of a command button. followinf is the code for identifying and saving MS Word:-
Do While (FindWindow("OpusApp", vbNullString)) <> 0
WinWnd1 = FindWindow("OpusApp", vbNullString)
ShowWindow WinWnd1, SW_SHOWNORMAL
Dim x As Word.Application
Set x = GetObject(, "Word.Application")
AppActivate "Microsoft Word"
x.ActiveDocument.SaveAs "C:\Word" & i & ""
x.Quit
Set x = Nothing
i = i + 1 'i is declared before as a static variable
Loop
This codes works fine if one or any number of Word Application (SDI) is opened. However if only one Word is opened and more than one document (MDI) is opened on that Word application then one document is saved and than the dialog box asking for saving the application popup and asks for file name. I want that it the dialog box shouldn't appear and it should save those MDI documents with different file names.
Anyone please help me .....
-
Jan 10th, 2003, 06:19 AM
#2
Look up the "Documents" collection in the word vba help file:
VB Code:
For Each aDoc In Documents
If aDoc.Saved = False Then aDoc.Save
Next aDoc
For the second part, the following will supress any messageboxes from being shown to the user whilst the code excecutes, just remember to set this back to true at the end of the procedure!
VB Code:
word.Application.DisplayAlerts = false
-
Jan 15th, 2003, 05:06 AM
#3
Thread Starter
Junior Member
Hi!
Thankyou for the help. Now I want to save PowerPoint, Excel etc. in the similar way. What "For.... Each.." should I use for Power Point and Excel? I have used the following:-
For Excel I used : For Each Workbook In x.Workbooks , which is working fine but looses one excel document if I open more than one document.
Power Point I used : For Each Presentation In x.Presentations
This code is not working atall.
Please suggest me how to proceed.
Regds,
Raju Deka
-
Jan 15th, 2003, 05:28 AM
#4
The workbooks item is a collection, this means you can take the count of the collection items and loop through them this way...
VB Code:
Dim intCounter As Integer
For intCounter = 1 To Workbooks.Count
Workbooks(intCounter).Save
Workbooks(intCounter).Close
Next intCounter
-
Jan 15th, 2003, 05:30 AM
#5
In powerpoint, it looks as though there's a presentations collection so this code should work also:
VB Code:
Dim intCounter As Integer
For intCounter = 1 To Presentations.Count
Presentations(intCounter).Save
Presentations(intCounter).Close
Next intCounter
-
Jan 16th, 2003, 03:50 AM
#6
Thread Starter
Junior Member
Hi! Thanks for the codes. It is working fine except if you open more documents(>3), it saves only the odd numbered documents and looses even numbered documents. So I removed the
"Presentations(intCounter).Close" part and putting another while loop at the outside. Now it is working perfectly fine.
Now I want to save "Outlook" , "Binder" etc. What should I use in "For.. Each".
Waiting for your reply...
-
Jan 16th, 2003, 06:12 AM
#7
To be honest I have no idea!
If you go into the code window/ide and type the following:
Outlook.application.
or Binder.application
you'll have access to all the properties & methods the application object contains. When you type that last dot after the word application above, scroll down the list until you see something which looks like a collection (such as documents or worksheets etc.) & try this in a for....each loop.
-
Jan 16th, 2003, 02:42 PM
#8
Thread Starter
Junior Member
Hi!
First I included the reference and did it like that only, but couldn't find anything favourable so that I can activate and save a document like Word or excel. I don't have any books so that I can refer automation or MSDN also doesn't have the examples I am looking for. If you can please suggest me something....
-
Jan 17th, 2003, 07:21 AM
#9
For Outlook it looks as though the windows are termed "Explorers" & are held in an Explorers collection, try this one:
VB Code:
Dim intCounter As Integer
For intCounter = 1 To Explorers.Count
Explorers(intCounter).Save
Explorers(intCounter).Close
Next intCounter
-
Jan 17th, 2003, 07:30 AM
#10
For the Binder application, it looks as though the collection is termed "Section". I'm not sure how to code this one so I'd advise you to perform a search on the www.msdn.microsoft.com site for binder and section collection together...
-
Jan 19th, 2003, 04:39 AM
#11
Thread Starter
Junior Member
disablle keyboard
Hi!
Thanks for the codes. I have solved most of my office automation problems with your help. Now I want to save non office documents like Notepad, Wordpad, Paint etc. I have done all this through APIs and "Sendkey" function and are working fine. Now I want to disable the keyboard(Physical) so that when my software is saving documents with "Sendkeys" function user shouldnot be able to edit any document by keyboard. Otherwise my software fails to save some documents. Can you suggest me some API or function to disable the physical keyboard.
-
Jan 20th, 2003, 03:40 AM
#12
Hiya raju,
I'm not sure off the top of my head on this one, sorry.
If you could you post this as a new question on the forums, someone else should be able to help you for this part ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|