Jump to content

Using COM of ActiveX with Wordpad


simbo
 Share

Recommended Posts

Hello All

I've written a program that produces RTF files. I have 2 questions:-

1) As I don't know whether or not the end user will have MS Office or OpenOffice, I want to open the files in Wordpad because I know that every Windows user has got Wordpad. If I use shellexecute they open using the default RTF reader, in my case MS Word. Is there some way I can I force them to open in Wordpad without having to change the File Association in Control Panel?

2) Wordpad ignores the margin settings in my documents, and instead uses default settings. Can I use COM or ActiveX or something else to change the margin settings directly from my script. I know I could simulate the keystrokes needed by I think that looks a bit amateurish

Many thanks in advance

Simbo

Link to comment
Share on other sites

Hello simbo,

1 ) Open Wordpad using shellexecute and pass the RTF file as an argument.

Be advised that you may need to wrap the RTF path with quotes to account for paths that contain spaces.

$wordpad = "C:\Program Files\Windows NT\Accessories\wordpad.exe"
$RTFdoc = "C:\Test.rtf"
ShellExecute( $wordpad, '"' & $RTFdoc & '"'  )

2 ) The following registry key appears to persist the margin settings between sessions. Before distributing your script you may be able to open the RTF, change the margins manually, close the app and then capture the data from this key (i.e., RegRead ). Then use RegWrite in your script to change the user's setting to match your's before opening wordpad.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Wordpad\Options\PageMargin

Hope this helps,

Zach...

Edited by zfisherdrums
Link to comment
Share on other sites

Many thanks guys - I can't believe how easy that was!

My program is now up and running (well, apart from the million and one ways I keep thinking of to feature-bloat... err... I mean improve it's functionality!

Thanks again

Simbo

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...