Solved

Open/Save/Close .rtf in Wordpad Programatically

Posted on 2006-11-03
5
2,211 Views
Last Modified: 2013-12-25
Hi,

Is there a way to Open a Word Document (xxx.rtf) using WordPad and then resave within Wordpad programatically.
I can manually do this with out any problem.

I need this because we have some .rtf files which fail to open using word but with Wordpad they open fine.

Word fails to open and the error description i get is

"Word was unable to read this document.  It may be corrupt.
Try one or more of the following:
* Open and Repair the file.
* Open the file with the Text Recovery converter.
 (S:\Triumph\T0222\...\T0222-E00000346.doc)"

If i open this doc in Wordpad, resave and then open up the doc in MS-word mannualy, it works fne.

Any help will be greatly appreciated.

Thanks,
DT
0
Comment
Question by:dtruong98
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 17869434
Hi dtruong98,

Wordpad does not support automation (like Word) so it cannot be done.

Cheers!
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 17870323
I wrote this sample for german wordpad. It uses
SendKeys "%f"
to open a file.

If you use the english wordpad you have
modify the SendKeys combination.






Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
Visible = False
Shell "C:\Programs\WORDPAD.EXE", vbNormalFocus
mySleep 30 'wait three seconds

SendKeys "^o" 'open file = CTRL+o

Clipboard.Clear
Clipboard.SetText "c:\test.doc"     ' file name to open

SendKeys "^v"           'CTRL+v    inserting the file name from clipboard
SendKeys "%f"           'sends ALT+f      open file

mySleep 80                'wait 8 seconds
SendKeys "^s"            'CTRL+s      save file

mySleep 20 'wait 2 seconds

MsgBox "file saved"
End

End Sub



Sub mySleep(ByVal deciSeconds As Long)
    For r = 1 To deciSeconds: Sleep 100: DoEvents: Next
End Sub
0
 

Author Comment

by:dtruong98
ID: 17883001
Hi Elmar,

I am using the following code:

Shell "C:\Program Files\Windows NT\Accessories\WordPad.exe C:\temp\test.doc"
AppActivate "test.doc - WordPad"
SendKeys "^s"    ---Ctrl S ---Used to save file
SendKeys "%(fs)" --- Alt F and S  ---Also can be used to save file
SendKeys "%(fx)"  ---Alt F and X -  Close wordpad

I can succesfully open the "C:\temp\test.doc" file in wordpad, but unable to save and exit wordpad.

I tried putting the sleep commands but with no use.

Any ideas ??

Thanks,
DT
0
 
LVL 17

Accepted Solution

by:
vb_elmar earned 500 total points
ID: 17883486
>>SendKeys "%(fs)" --- Alt F and S  ---Also can be used to save file

Sendkeys can send only   **one**   char. It must be

SendKeys "%f" '-send Alt F
SendKeys "s"    '-send S
0
 

Author Comment

by:dtruong98
ID: 17884226
The following code worked:

Shell "C:\Program Files\Windows NT\Accessories\WordPad.exe C:\temp\test.doc", vbMaximizedFocus
Sleep 5000 'Sleep 5 seconds
AppActivate "test.doc - WordPad"
SendKeys "^s" 'Save using Ctrl S
AppActivate "test.doc - WordPad"
AppActivate "test.doc - WordPad"
CloseWordPad (Done using an API call)

Thanks Elmar for your help.

DT
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question