Solved

Word 2000 and WordPerfect VB integration

Posted on 2002-04-30
12
307 Views
Last Modified: 2007-12-19
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
Comment
Question by:jtjcomp
[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
  • 7
  • 4
12 Comments
 
LVL 1

Expert Comment

by:S2
ID: 6981450
Dim WordApp1 As Word.Application

Set WordApp1 = CreateObject("word.application")

and you can continue from here.
0
 
LVL 1

Expert Comment

by:soferstam
ID: 6981485
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
 
LVL 1

Expert Comment

by:soferstam
ID: 6981519
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 1

Expert Comment

by:soferstam
ID: 6981529
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
 
LVL 1

Author Comment

by:jtjcomp
ID: 6981556
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
 
LVL 1

Expert Comment

by:soferstam
ID: 6981564
Yes,sorry..
You must make it visible:
objWord.Visible = True
0
 
LVL 1

Author Comment

by:jtjcomp
ID: 6981568
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
 
LVL 1

Author Comment

by:jtjcomp
ID: 6981572
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
 
LVL 1

Author Comment

by:jtjcomp
ID: 6981592
But after the save I want to leave the editor open
0
 
LVL 1

Expert Comment

by:soferstam
ID: 6981605
ObjDoc.Activate
ObjDoc.Save  or .saveas ....
Is that the question?
0
 
LVL 1

Accepted Solution

by:
soferstam earned 100 total points
ID: 6981607
The editor will remaining open after the save
0
 
LVL 1

Expert Comment

by:soferstam
ID: 6981685
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

728 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