Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

Word 2000 and WordPerfect VB integration

Here is my question.  I need to shell out to either word or word perfect (depending on the user) and save a new document according to what the user typed into the vb app(They type the document name).  Currently I'm using send keys and waiting for the editors to open, when they open I send  the keys the alt F and S then send keys the Document name, then send keys another alt s.  

This process works, but it is ugly.  I dont want to use the send keys.  

Is there anyway to back door into the editors??  So in other words I will shell to the editor, but then instead of using sendkeys to implement the save I use something else.


Any thoughts would be helpful

J.
0
jtjcomp
Asked:
jtjcomp
  • 7
  • 4
1 Solution
 
S2Commented:
Dim WordApp1 As Word.Application

Set WordApp1 = CreateObject("word.application")

and you can continue from here.
0
 
soferstamCommented:
Sure,
To open word:
Add reference to word type library(or use create object-this is better if you don't know what MSword installed on a client)
Open word:
''''''''''''''''''''''''
Set objWord = New Word.Application
Set ObjDoc = objWord.Documents.Add
(or Set ObjDoc = objWord.Documents.Open(the path))
''''''''''''''''''''''''
To write:
ObjDoc.Sections(1).headers(wdHeaderFooterPrimary).Range.text=""
ObjDoc.Sections(1).headers(wdHeaderFooterFirstPage).Range.text=""
ObjDoc.Sections(1).Footers(wdHeaderFooterFirstPage).Range.text=""
ObjDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range.text=""
ObjDoc.Range.test=""
to close:
''''''''''''''''''''''''
For Each ObjDoc In objWord.Documents
    If Not TypeName(ObjDoc) = "Nothing" Then
    ObjDoc.Close False
    Set ObjDoc = Nothing
    End If
Next
''''''''''''''''''''''''
And,if you don't know the word object module,you can alway's record macro in word and copy this code into your vb application:
1.Start record macro.
2.Do in word whatever you have to de
3.Stop recording and go to VBA editor.
4.Copy this code into your vb procedure.

To save in different formats:
ObjDoc.SaveAs FileName:=SaveTo, fileformat:=wdFormatDocument

Search for Q235928 for supported file formats
0
 
soferstamCommented:
More about formats:
To save word in defferent formats,you have to:
1.Install this format by open a new docoment and trying to save it in format you wish.It will install automatically file converter.
2.Use know constants :
"wdFormatDocument"
"wdFofmatDOSText"
"wdFormatDOSTextLineBreaks"
"wdFormatEncodedText"
"wdformathtml"
"wdformatrtf"
"wdFormatRTF"
"wdformattemplate"
"wdformattext"
"wd"wdFormatUnicodeText"
"formattextlinebreaks"
Example:
ObjDoc.SaveAs FileName:=SaveTo, fileformat:=wdFormatDocument


Or,use class names:
CnvClassName="wrdprfctdos51"
MyPath="" 'without extention !
     For Each FCnv In objWord.FileConverters
      If Trim(LCase(FCnv.ClassName)) = Trim(LCase(CnvClassName)) Then
      On Error Resume Next
      MyPath=PyPath & "." & FCnv.Extensions
      ObjDoc.SaveAs FileName:=MyPath, fileformat:=FCnv.SaveFormat
           If Err.Number <> 0 Then

               End If
      End If
      Next
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
soferstamCommented:
Sorry,to busy with something else..
This is possible class names you can use.
You can find much more info on msdn.
 
MS-DOS Text with Layout
 MS-DOS Text with Layout
 
Text with Layout
 Text with Layout
 
Word 2.x for Windows
 MSWordWin2
 
Word 4.0 for Macintosh
 MSWordMac4
 
Word 5.0 for Macintosh
 MSWordMac5
 
Word 5.1 for Macintosh
 MSWordMac51
 
WordPerfect 5.0
 WrdPrfctDOS50
 
WordPerfect 5.1 for DOS
 WrdPrfctDOS51
 
WordPerfect 5.x for Windows
 WrdPrfctWin
 
WordPerfect 5.1 or 5.2 Secondary File
 WrdPrfctDat
 
WordPerfect 5.0 Secondary File
 WrdPrfctDat50
 
Works 4.0 for Windows
 MSWorksWin4
 
Word 6.0/95
 MSWord6Exp
 
Word 97-2000 & 6.0/95 - RTF
 MSWord6RTFExp
 
0
 
jtjcompAuthor Commented:
soferstam

I'm trying your code now to open the word editor.  I have set my references and added the following lines

Dim WordApp As New Word.Application
Dim WPApp As New WordPerfect.Application

Set WordApp = CreateObject("word.application")
Set WordDoc = WordApp.Documents.Add

When I run through this in code, WinWord.exe shows up in the taskmanager but the window does not open and I can not find it anywhere on the desktop.  I'm I missing something
0
 
soferstamCommented:
Yes,sorry..
You must make it visible:
objWord.Visible = True
0
 
jtjcompAuthor Commented:
soferstam

I'm trying your code now to open the word editor.  I have set my references and added the following lines

Dim WordApp As New Word.Application
Dim WPApp As New WordPerfect.Application

Set WordApp = CreateObject("word.application")
Set WordDoc = WordApp.Documents.Add

When I run through this in code, WinWord.exe shows up in the taskmanager but the window does not open and I can not find it anywhere on the desktop.  I'm I missing something
0
 
jtjcompAuthor Commented:
Ok, so now I see the editor, but there is not a wordapp.save method or is there?  I know the name of the document I just need to do a save for it when the editor opens.

J
0
 
jtjcompAuthor Commented:
But after the save I want to leave the editor open
0
 
soferstamCommented:
ObjDoc.Activate
ObjDoc.Save  or .saveas ....
Is that the question?
0
 
soferstamCommented:
The editor will remaining open after the save
0
 
soferstamCommented:
You will leave the editor open,
but sometime you still need to close it.
Make sure you completely close it,as follows:


For Each ObjDoc In objWord.Documents
   If Not TypeName(ObjDoc) = "Nothing" Then
   ObjDoc.Close False
   Set ObjDoc = Nothing
   End If
Next
If Not TypeName(objWord) = "Nothing" Then
  If objWord.Documents.Count = 0 Then objWord.Quit False
  Set objWord = Nothing
End If

Good luck!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now